我专门在服务器上使用主干,这可能有点不寻常,但除了手动删除所有引用之外,我只是不知道如何永久删除模型。
var Foo = Backbone.Model.extend({
defaults: {
a: 'hello',
b: 'there',
c: 'friend'
}
});
var foo = new Foo();
var Bar = Backbone.Model.extend({
defaults: { foo: foo }
});
alert(foo.get('a'));
foo.destroy();
alert(foo.get('b'));
foo = null;
alert(new Bar().get('foo').get('c'));
预期输出:你好
; 呃?
; 嗯?
实际输出:hello
; 那里
; friend
( http://jsfiddle.net/Exj4U/1/ )
我在这里误解了什么吗?这是您只需取消引用它并不管它的事情之一吗?
最佳答案
我不确定...但你不能使用对象。 您可以:
foo = undefined;
foo = null;
foo
是一个对象 .destroy()
没有任何作用,因为它是一个可以在 BB Model 上使用的方法,你可以使用 .destroy()
在 Foo
上。
Foo.destroy();
还有:
alert(new Bar().get('foo').get('c'));
之所以有效,是因为您在 foo = null
之后定义了 Bar
模型
var Bar = Backbone.Model.extend({
defaults: { foo: foo }
});
等于:
var Bar = Backbone.Model.extend({
defaults: { foo: {
//... foo object content
defaults: {
a: 'hello',
b: 'there',
c: 'friend'
}
//...
}
});
关于javascript - 删除backbone.js中的模型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20939503/