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