0
我的代碼有一個瘋狂的問題。我試圖實施this jsfiddle code奇怪的數據綁定問題
在我的代碼中,但我沒有成功。這是我做了什麼:
視圖模型:
viewModelInbox = function(){
query: ko.observable('');
var checked = false,
mainData = ko.observableArray([]),
showView = ko.observable(),
currentView = ko.observable(),
approve = function(){
},
disapprove = function(){},
toggle = function() {
if(checked){
$.each(mainData(), function(){
this.checkB(false);
});
checked = false;
return;
}
if(!checked){
$.each(mainData(), function(){
this.checkB(true);
});
checked = true;
return;
}
};
viewModelInbox.mainData = ko.dependentObservable(function() {
var search = this.query().toLowerCase();
return ko.utils.arrayFilter(viewModelInbox, function(test) {
return test.name.toLowerCase().indexOf(search) >= 0;
});
}, viewModelInbox);
return {
mainData: mainData,
showView: showView,
currentView: currentView,
approve: approve,
disapprove: disapprove,
toggle: toggle
};
},
的mainData
觀察到的數組保存有部分值名稱,代碼,日期等
我的問題是,我得到這個錯誤:
TypeError: this.query is not a function
var search = this.query().toLowerCase();
我敢肯定,我錯過了一些非常小的東西,但因爲我總共n在knockoutjs oob我不能發現它。
我使用的第2結構,但逗號(,)似乎無法正常工作。它要求(;)而不是它。 :s – Slim
如果您使用第二個結構,則應刪除'function',並使用':'而不是'=' –