0
我想映射一些數據(從jQuery $ .ajax調用返回)到視圖模型,但由於某種原因嵌套數組未映射。Knockout映射插件不映射陣列內部模型
<p>Name: <input data-bind="value: Name" /></p>
<p>Age: <input data-bind="value: Age" /></p>
<p>Friends: <span data-bind="text: Friends.length"></span></p>
<script type="text/javascript">
var viewModel = null;
var data = { "Name": "Simon", "Age": "24", "Friends": [{ "Name": "Bill", "Age": "24" }, { "Name": "Peter", "Age": "21"}]};
viewModel = ko.mapping.fromJS(data);
ko.applyBindings(viewModel);
</script>
在這個簡單的例子,西蒙沒有朋友......