我有類似如下:子視圖模型拋出異常在Internet Explorer 8
var ChildViewModel = function (viewModel) {
// state
this.viewModel = viewModel;
this.index = ko.dependentObservable(function() {
return this.viewModel.selections().indexOf(this);
}, this);
this.remove = function() {
this.viewModel.removeSelection(this);
};
this.moveUp = function() {
this.move(-1);
};
this.moveDown = function() {
this.move(1);
};
this.move = function (direction) {
var i = this.index();
this.remove();
this.viewModel.selections.splice(i + direction, 0, this);
};
// additional properties
};
var viewModel = {
selections: ko.observableArray(),
removeSelection: function (item) {
this.selections.remove(item);
},
addSelection: function (event) {
var child = new ChildViewModel(this);
this.selections.push(child);
}
};
ko.applyBindings(viewModel);
當我打電話addSelection
,我已經得到了KnockoutJS圖書館內Object doesn't support this property or method
例外。我的應用程序在Firefox 3.6和Chrome中運行良好。我在IE8中遇到了異常。我正在使用KnockoutJS的版本2.0
1.3 Beta
。
我在做什麼錯?
你在使用淘汰賽的縮小版嗎?如果是這樣,也許給未壓縮的版本一個鏡頭,看看哪一行在敲除錯誤,它可能會提供一個線索可能的原因。 – 2011-12-21 13:14:25
@AlexKey - 我會更新我的問題。 – 2011-12-21 13:16:08
@Daniel:我的錯誤 - 我沒有意識到Knockout實現了'indexOf()'。 – 2011-12-21 13:43:10