【发布时间】:2014-07-02 17:54:46
【问题描述】:
我有以下视图模型(到目前为止):
var TradeViewModel = function (config) {
var self = this;
var mapping = {
'result': {
'stuff': {
update: function(options) {
return options.data + 'foo!';
}
}
}
}
ko.mapping.fromJS(config, mapping, self);
};
我的数据如下所示:
{
"result": {
"stuff": [
{
"foo": "bar",
"important": "computeme",
},
{
"foo": "baz",
"important": "computemetoo",
}
],
"otherstuff": [
]
}
}
我看到的标准文档涵盖了嵌套关联数组,但对常规数组并没有多说。就我而言,我认为我需要一个函数来迭代“stuff”中的每个项目并计算新值,从而产生“computemefoo!”和“computemetoofoo!”,例如。我是淘汰赛新手,对这个有点迷茫......
jsfiddle: Fiddle with me 基本模型位于路径 /2/ 中,您可以通过递增 /3/、/4/ 等来查看我正在尝试的内容。
【问题讨论】:
-
按要求添加到帖子中——这是个好主意
标签: knockout.js mapping viewmodel