本文介绍了来自json的knockout.js部分映射的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在基因敲除网站的文档上,他们说,当您从服务器取回数据时,您可以执行以下操作:

On the knockout.js site's documentation they say that when you get data back from the server you can do this:

// Every time data is received from the server:
ko.mapping.fromJS(data, viewModel);

我想将数据部分映射回我的对象​​模型.有可能吗?

I'd like to partially map the data back into my object model. Is that possible?

我有一个viewModel.jobs [i] .JobType子对象,所以我想做这样的事情:

I have a viewModel.jobs[i].JobType child object, so I'd like to do something like this:

ko.mapping.fromJS(data.jobType, viewModel.jobs[i].JobType);

...意味着我只想将来自服务器结果的jobType映射到该特定作业的JobType字段中.

... meaning I'd like to just map in the jobType from the result from the server into this specific job's JobType field.

...另外请记住:

// does not work because viewModel.jobs[i].JobType() is not a function.
viewModel.jobs[i].JobType(data.JobType);

推荐答案

此方法有效:

ko.mapping.fromJS(data.job,viewModel.jobs [i]);

ko.mapping.fromJS(data.job, viewModel.jobs[i]);

这篇关于来自json的knockout.js部分映射的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-19 10:15