我有一个页面显示数据库中的项目列表和一个用于添加新项目的文本框。首次呈现页面时,列表在 IE 中正确显示,但是当我添加新项目时,列表未在 IE 8 中更新。这在 chrome 中正常工作。这是我的代码:
self.ListOfDepartments.GetListOfAllDepartments = function () {
$.getJSON('/Department/ListAllDepartments', function (data) {
var mapped = ko.mapping.fromJS(data);
self.ListOfDepartments(mapped);
});
};
self.AddDepartmentModel.AddDepartment = function () {
self.errors = ko.validation.group(this, { deep: true, observable: false });
if (self.AddDepartmentModel.errors().length == 0) {
$.ajax({
url: "/Department/Add/",
type: 'post',
data: ko.toJSON(self.AddDepartmentModel),
contentType: 'application/json',
success: function (result) {
$('#success').html('Department Added Successfully.');
$("#success").dialog({
dialogClass: 'noclose',
autoOpen: true,
show: "blind",
hide: "explode",
modal: true,
open: function(event, ui) {
setTimeout(function() {
$('#success').dialog('close');
}, 3000);
}
});
Department.DepartmentName(null);
Department.DepartmentName.isModified(false);
self.ListOfDepartments.GetListOfAllDepartments();
}
});
} else {
self.AddDepartmentModel.errors.showAllMessages();
return;
}
};
HTML:
<div data-bind="foreach: ListOfDepartments()">
<div data-bind="text: DepartmentName" class="margin textStyle"></div>
</div>
如果添加成功,则调用 GetLIstOfAllDepartments 时,我的页面列表不会在 IE 中更新。IE有什么特别需要做的吗?