Why is one ko.mapping.fromJS working and other one not?

僤鯓⒐⒋嵵緔 提交于 2019-12-22 09:35:32

问题


I have a class a class named Foo and Foo contains Model. I am doing a ko.applyBinding on Foo. The Foo class has a function which retrieves JSON from server and then I do:

 self.Model = ko.mapping.fromJS(result);

where self is instance of Foo and result is JSON. This works 1st time. However, when 2nd item I retrieve data from server it just doesn't work.

But if the above line to:

 self.Model = ko.mapping.fromJS(result, {}, self);

it works.

Can anybody tell me why is the 1st one not working and 2nd one works?


回答1:


Your second line should be:

ko.mapping.fromJS(result, {}, self.Model);


来源:https://stackoverflow.com/questions/10960479/why-is-one-ko-mapping-fromjs-working-and-other-one-not

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