1

每次我调用“this.model = new Unidade();”时,this.model 都会将最后一个值的一些值保存在那里。

this.model.id => 变为 null,但其他属性保留最后一个模型的值。

模型来源

window.Unidade = Backbone.Model.extend({

urlRoot : $urlPadrao + "cliente/externo/unidade",

defaults: { // setting defaults to null or "" 
},

initialize: function () {
    ... // Just initialize the validators methods    
},

getDefaults: function() {
    // returns the same values of defaults
    // since I can't get a "new" model
}

});

在我看来:

this.model = new Unidade();
// this.model may be already populated... I'm trying to create a new one
// that's the problem, it keeps some values of the last one
// Shouldn't give me a new model populate with the defaults? 

为了记录,我没有弄乱原型。

4

2 回答 2

0

我设法获得了这个巫术的来源,不知何故,主干正在获取这些属性,然后在模型的原型上进行设置,从而使它们成为静态的。好诡异。

于 2013-04-08T11:52:30.880 回答
0

这些属性是数组吗?由于我在本文中发现的内容,我发现我的基本上被视为传递引用:

Backbone.js 模型中的数组本质上是静态的?

于 2013-04-10T22:59:07.457 回答