KnockoutJS 中的子视图模型在 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 does not support this property or method
异常。我的应用程序在 Firefox 3.6 和 Chrome 中运行良好。我在 IE8 中遇到异常。我正在使用 KnockoutJS 2.0 1.3 Beta 版本。
我做错了什么?
I have something like the following:
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);
When I call addSelection
, I have get a Object doesn't support this property or method
exception inside the KnockoutJS library. My application works fine in Firefox 3.6 and Chrome. I get the exception in IE8. I'm using version 2.0 1.3 Beta of KnockoutJS.
What am I doing wrong?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
好吧,我有两个不同的问题。
首先,我删除了获取数组值的方法,而是使用可观察数组。
另外,我正在设置
for
属性。 IE 抱怨for
是一个关键字。Ok i had 2 different problems.
First, I removed the method to get the value of the array, instead used the observable array.
Also, I was setting the
for
attribute. IE complains about thatfor
is a keyword.不要使用自闭合标签,如
。当您使用淘汰赛时,它也会在 IE8、IE7 中导致问题。
Do not use self closing tags like
<span data-bind='text: Text' />
. It also can cause problems in IE8, IE7 when you use knockout.