问题
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;
});
}
};
回答1:
I had the same issue found here
and I just had to refer to my objects with long data-binds like members.events.title
instead of title
.
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.
来源:https://stackoverflow.com/questions/16453003/knockout-js-and-with-binding-in-ie8-corrupts-page