骨干定义收集的自定义方法



我要为fetch()方法创建自定义包装器方法:

let personCollection = Collection.extend({
    mainIndex: 'id',
    url: 'https://jsonplaceholder.typicode.com/posts',
    model:Person,
    findAll:function(){
      return this.fetch({url:this.url, type: 'POST'});
    }

});

在Findall()方法中,我想要更改URL路径和HTTP方法,但是上述代码发送获取请求

这可能是一个问题,查看此代码:https://github.com/ampersandjs/ampersand-sync/blob/master/core.js#l73

  // If passed a data param, we add it to the URL or body depending on request type
  if (options.data && type === 'GET') {
      // make sure we've got a '?'
      options.url += includes(options.url, '?') ? '&' : '?';
      options.url += qs.stringify(options.data);
      //delete `data` so `xhr` doesn't use it as a body
      delete options.data;
  }

type变量来自methodMap,即使您可能已将其覆盖。

仍然,如果不进行调试,我无法确定。您应该逐步浏览它,然后查看发送到xhrImplementation的内容。

最新更新