使用这样的 JSON:
JSON字符串
{
"SelectedOption" : {},
"Options" : [
{ "ID": 0, "Name": "Zero" },
{ "ID": 1, "Name": "One" }
]
}
问题是:如何告诉映射插件该SelectedOption
属性是ko.observable?
客户代码
var _json = '{
"SelectedOption" : {},
"Options" : [
{ "ID": 0, "Name": "Zero" },
{ "ID": 1, "Name": "One" }
]
}';
var viewModel = ko.mapping.fromJSON(_json);
ko.applyBindings(viewModel);
我写了一个 jsfiddle 来显示问题 http://jsfiddle.net/BvVce/3/