问题
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