KnockoutJS - Update ViewModel / Mapping Plugin

时间秒杀一切 提交于 2019-12-03 13:19:59

If you look at the 'Specifying the update target' on the mapping documentation, you can specify a target for the mapping.

This should mean that you can say:

if (!viewModel)
   viewModel = ko.mapping.fromJS(data);
else
   ko.mapping.fromJS(data, {}, viewModel); 

This way you will create a view model on the initial load, then update that view model for any subsequent loads.

Afonso Praça

Using mapping plugin I did this

ko.mapping.fromJS(JsonResponse, myObservable());

That's all.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!