我想弄清楚MVC/Durandal/Knockout項目爲什麼我不能將 ContractsList() = ko.observableArray();
綁定到第4級foreach中。 它工作正常,直到3級。嵌套ForEach Knockout 2.2.1不顯示達到第四級
這是我試圖綁定的Json。
{"Contracts":
{
"Contract":
[
{
"NrContract":null,
"IdStore":"5",
"FlagStatus":"P",
"Date":"30/11/2017",
"Sale":"3168.23",
"DsName":"TEST1",
"Items":
{
"Item":
[
{"NrItems":"1","VlTotalItems":"1112.23","DsItems":"3123123"},
{"NrItems":"1","VlTotalItems":"2056","DsItems":"bbb"}
]
}
},
{
"NrContract":null,
"IdStore":"5",
"FlagStatus":"P",
"Date":"30/11/2017",
"DsName":"TEST2",
"Items":
{
"Item":[
{"NrItems":"7","VlTotalItems":"7785,61","DsItems":"3123123"},
{"NrItems":"1","VlTotalItems":"3","DsItems":"oi"}
]
}
}
]
}
}
的foreach簡化:
<div data-bind='foreach: ContractsList'>
<div data-bind='foreach: Contract'>
<div data-bind='foreach: Items'>
<div data-bind='foreach: Item'>
<span data-bind='text: DsItems'></span>
</div>
</div>
</div>
'Items'是一個對象,而不是一個數組。改用'Items.Item'。 – user3297291