我的问题是如何更新集合中的模型?这是我正在做的。在页面加载时,我获取联系人列表。在一个视图中,我将这些联系人列在无序列表中。每个联系人都是可点击的,这会将您带到编辑表单。一旦你改变了联系人,你就可以保存联系人。这将带你到一个方法,将修改后的模型保存回集合。你会如何做到这一点?在骨干文档中没有更新方法(或者至少我没有看到它)。我创建了一个这样做的方式,但我不确定它是否是首选的Backbone方式。那就是:更新集合中的模型
updatePlan : function()
{
//unique ID of the model
var id = $('input[ name=id ]').val();
//remove the old model from the collection
this.collection.remove(this.model);
//add the updated model to the collection
this.collection.add(this.model);
}
你会觉得会有这样的功能:
updatePlan : function()
{
this.collection.update(this.model);
}
感谢您的帮助