2017-03-03 113 views
0

我想创建取(定制包装方法)自定义的方法方法是这样的:骨干定义集合

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方法, 但上面的代码发送GET请求

回答

0

这可能是一个&符号的问题,看着这个代码: 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的内容。