0
我有一个模型,这个方法 -对象渲染在骨干中没有任何方法调用
getDisplayedData: function(){
data = this.get('data')
displayedData = this.get('displayedData')
title = this.get('title')
newData = [];
dataToShow = this.get('dataToShow');
_.each(dataToShow, function(value,key,list){
nData = data.length;
for(i = 0; i < nData ; i++){
row = data[i];
if(row[title] == value){
newData.push(row);
}
}
});
this.set("displayedData", newData);
return newData;
}
这是它如何被called-
this.collection.each(function(model,key,list){
data = model.getDisplayedData();
});
我得到这个错误 -
Uncaught TypeError: Object render has no method 'call'
我知道这是因为这是一个真正的集合对象,而不是DataModel。我如何绑定它,以便它引用模型?
在我的模型的init方法我做的这 -
initialize: function(){
console.log("INIT MODEL");
console.log(this);
return this;
},
这是打印 -
r {cid: "c2", attributes: Object, _changing: false, _previousAttributes: Object, changed: Object…}
_changing: true
_events: Object
_pending: false
_previousAttributes: Object
attributes: Object
changed: Object
cid: "c2"
collection: r
getDisplayedData: function() { [native code] }
__proto__: s
没有固定的位置 - 这就是问题所在(我认为)。
你的错误没有被在getDisplayedData提高,因为在它的渲染“没有提及。也许你在某种观点上对变革事件有约束力?另一件事:你的代码非常奇怪,我不确定它在没有浏览代码的其余部分的情况下做了什么,但是在第一个方法已设置但没有使用的情况下显示数据。循环中的数据相同。毕竟,你为什么要调用这个方法并将数据放入数据var?你之前是否宣布过这些变数?在我看来,你有很多全局变量。 – Cristopher
使用分号。你的代码是一致性很糟糕。 – naomik