我的问题是如何更新集合中的模型?这就是我正在做的事情。在页面加载时,我获取联系人列表。在一个视图中,我在一个无序列表中列出了这些联系人。每个联系人都是可点击的,这将带您进入编辑表单。对联系人进行更改后,您可以保存该联系人。这将带您进入将更改的模型保存回集合的方法。你会怎么做?在骨干文档中没有更新方法(或者至少我没有看到它)。我创建了一种方法来做到这一点,但我不确定它是否是首选的 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 );
}
谢谢您的帮助