假设我们有以下对象:
var gridViewModelJs =
{"GridViewModel":{"Rows":[{"RowNumber":"1","Id":"6","Name":"FullNameOfUser","NumberOfUsers":"12","RegistrationDate":"10/15/2013"}],"FoundItems":"4","CurrentPage":1,"TotalPages":1,"ItemsPerPage":50,"PagingLinks":""},
"EntityModel":{"Id":0,"PermissionIds":null,"Name":null,"NumberOfUsers":0,"PersianRegistrationDate":null,"RegistrationDate":"0001-01-01T00:00:00","Authorizations":null,"Users":null,"Contents":null}};
var KoEntityViewModel = ko.mapping.fromJS(gridViewModelJs);
ko.applyBindings(KoEntityViewModel);
上面的代码有效,用于更新
KoEntityViewModel.
,我使用了以下代码:// receivedData is data that returns from jQuery Ajax
// I'm dead sure `receivedData` is correct
var doneFunc = function (receivedData) {
ko.mapping.fromJS(receivedData, KoEntityViewModel.EntityModel);
showDetailsBlock();
};
但是
KoEntityViewModel.EntityModel
中没有任何更新。请指导我如何更新上述示例中的
KoEntityViewModel.EntityModel
最佳答案
在应用绑定后更新映射时,请使用三个参数:
ko.mapping.fromJS(receivedData, {}, KoEntityViewModel);