静静地使用Backbone.Collection.get(id)

pra*_*n64 1 collections backbone.js

好像在我调用了一个backbone.js集合时,它通过cookie传递id,而不是传递给我的GET方法.在请求标题中它出现如下:

饼干:帖= ag5kZXZ-c29jcmVuY2h1c3IOCxIIUG9zdExpc3QYAQw; dev_appserver_login = "test100@example.com:错误:114323764255192059842"

这就是我所拥有的:

来电:

postCollection.get(id)
Run Code Online (Sandbox Code Playgroud)

和get方法:

def get(self, id):
Run Code Online (Sandbox Code Playgroud)

我想在get方法中使用id而不是必须使用cookie.

abr*_*ham 5

可能最好的方法是完成此任务,如下所示.

var model = collection.get(id);
// If the model is not present locally..
if (!model) {
  // Add empty model with id.
  model = collection.add([{id: id}]);
  // Populate model attributes from server.
  model.fetch({success: successCallback, error: errorCallback });
}
Run Code Online (Sandbox Code Playgroud)

collection.get(id) 不应该向后端提出请求.