当我在模型上调用主干销毁方法时,我收到此错误。
A "url" property or function must be specified
我正在使用本地集合,并且我在网上某处看到在 destroy 方法中调用了 save 方法来查找 url。有没有解决的办法。如何防止错误发生。
最佳答案
正如nrabinowitz
在评论中所说,destroy是为了从服务器中删除,实际上不会从集合中删除。
如果问题在于将其从集合中删除(如评论中所示)...
模型可以通过模型的 collection
属性访问其集合。
var Model = Backbone.Model.extend({
defaults:{ name: 'bob' }
}),
Collection = Backbone.Collection.extend({
model: Model
});
var c = new Collection([{ name: 'joe'}, {name: 'h'}, {name: 'bob'}]);
var m = c.at(1); // get model at index 1 name = h
m.collection.remove( m ); // access the collection via the model we pulled out
console.log( c.length ); // only 2 models within :)
关于backbone.js - 主干破坏错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9609967/