0
我已經將實例存儲添加到了我的主幹模型中。當我手動創建一個對象與它的工作原理,並返回一個新的或已經存在的模型。我怎樣才能將這個功能集成到骨幹集合中。 你能給我一個提示,我必須重寫哪些方法/方法?將實例存儲集成到Backbone Collection中
我的實例存儲的代碼如下所示:
define(function(require) {
var Backbone = require('backbone');
return Backbone.Model.extend({
constructor: function(attributes, options) {
var id = attributes ? attributes.id : undefined;
if(this.store[id])
return this.store[id];
Backbone.Model.prototype.constructor.apply(this, arguments);
if(id)
this.store[id] = this;
this.count[id] = this.count[id] ? this.count[id] + 1 : 1;
}
});
});
我很感謝任何想法或暗示!