2017-03-03 4 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'}); 
    } 

を});

私は、URLパスとHTTPメソッドを変更したいのfindAll()メソッド、 ではなく、上記のコードは、 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; 
    } 

ここで変数typemethodMapから得られますが、オプションで上書きされている可能性があります。

まだ、デバッグすることなく、わかりませんでした。あなたはそれを踏んで、xhrImplementationに送られるものを見なければなりません。

関連する問題