我知道这个错误已经出现过几次了,但是我仍然不确定如何使它正常工作。
我的魔力从这里开始:
var list_edit_member_view = new app.views.ListMemberEdit({
el: $("#enterprise_member_list_edit_container"),
list_ids: list_ids
});
list_edit_member_view.render();
然后加载此 View ( ListMemberEdit.js ),该 View 在render()中具有此 View :
this.list_edit_member_view = new app.views.CollectionView({
el: $("#enterprise_member_list_edit_container"),
collection: app.peers,
list_item: app.views.ListMemberEditSelection,
list_item_options: {list_ids: this.options.list_ids}
});
加载一个CollectionView View ,将其
list_item_options
呈现为模型 View 。.它位于此文件(ListMemberEditSelection.js
)中,当我执行this.destroy
时,它将返回:Uncaught Error: A "url" property or function must be specified
因此,这使我认为未定义Model或Model URL。我只是不确定将其放置在何处,因为它的工作原理与我执行大致相同操作的其他部分非常相似。
有什么想法吗?对于模糊性,我深表歉意。让我知道您还有其他想要看的东西!
我很好奇是否有可能看到此URL属性将在对象模型或集合本身中写入的位置。
最佳答案
这是因为destroy()
函数也会调用Backbone.sync
来更新服务器,而不仅是前端的模型。 http://backbonejs.org/#Model-destroy
因此,如果您使用REST同步数据,则需要在模型中设置url属性,以便Backbone知道将请求发送到哪里:
Backbone.Model.extend({
url: "http://myapi.com/"
})
为了提供更大的灵活性,您还可以设置urlRoot:http://backbonejs.org/#Model-urlRoot
关于backbone.js - Uncaught Error : A "url" property or function must be specified for a CollectionView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12917849/