为什么一个ko.mapping.fromJS工作而另一个不工作? [英] Why is one ko.mapping.fromJS working and other one not?

查看:176
本文介绍了为什么一个ko.mapping.fromJS工作而另一个不工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个名为Foo的类,而Foo包含Model。我在Foo上做了一个ko.applyBinding。 Foo类有一个从服务器检索JSON的函数然后我这样做:

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);

其中self是Foo的实例,结果是JSON。这是第一次。但是,当第二项我从服务器检索数据时,它就不起作用。

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.

但是如果上面一行是:

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

可行。

任何人都可以告诉我为什么第一个不工作而第二个工作?

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

推荐答案

你的第二行应该是:

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

这篇关于为什么一个ko.mapping.fromJS工作而另一个不工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆