2017-03-03 111 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的內容。