knockout.js和“with” IE8中的绑定会破坏页面 [英] knockout.js and "with" binding in IE8 corrupts page
问题描述
我在knockout.js中使用with绑定,并且在Chrome和IE9中它可以正常工作,但是当我移动到IE8时,表单不再提交了。我删除了有它做得很好。在Visual Studio中,with关键字为蓝色,告诉我这是一个保留字。 IE8还有吗?
I am using the "with" binding in knockout.js, and it works fine below in say Chrome and IE9, but when I move to IE8 the form doesnt submit anymore. I remove the "with" it does just fine. In Visual Studio the "with" keyword is blue telling me it's a reserved word. Is there anyway around this for IE8?
<form class="box clearfix" action="@Request.RawUrl" data-bind="with: members.events, form: { id: @Model.Event.Id }">
ko.bindingHandlers.form = {
init: function (element, valueAccessor) {
var value = ko.utils.unwrapObservable(valueAccessor());
$(element).find('button[type=submit]:last').click(function () {
if (typeof (value.submit) == 'function') {
value.submit();
} else {
app.call({
type: 'POST',
data: $(element).serializeObject(),
url: $(element).attr('action'),
success: function (result) {
if (value.replace) {
app.updateContainerWithHtml(result);
} else {
if (value && value.id == 0 && typeof(result) == 'string') {
window.location.hash = result;
} else {
if (typeof (value.callback) == 'function') {
value.callback(result);
}
}
if (value.hideSuccess == undefined && !value.hideSuccess) {
if (result.Url) {
app.showSuccess(result.Message, function() {
window.location.hash = result.Url;
});
} else {
app.showSuccess();
}
}
}
}
});
}
return false;
});
}
};
推荐答案
我只需要使用长数据绑定来引用我的对象,例如 members.events.title
而不是 title
。
and I just had to refer to my objects with long data-binds like members.events.title
instead of title
.
我的代码部分很小,因为它只是一个附件部分所以它并不太烦人。您可以尝试转义with,例如 data-bind ='with':
,就像你使用ko评论if if使它们与IE一起使用但我怀疑那会有效。
My section of code was small as it was just for an attachment section so it wasnt too annoying. You can try escaping the with, like data-bind="'with':
, like you do with the ko comments for if's to make them work with IE but I am doubtful that would work.
这篇关于knockout.js和“with” IE8中的绑定会破坏页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!