我正在试图找出一个MVC / Durandal / Knockout项目,为什么我无法绑定一个
ContractsList() = ko.observableArray();
进入第4级的foreach。
它工作正常,直到第3级。
这是我试图绑定的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>
答案 0 :(得分:2)
这是因为items
是一个对象而不是一个数组:
"Items":
{
"Item":[
{"NrItems":"7","VlTotalItems":"7785,61","DsItems":"3123123"},
{"NrItems":"1","VlTotalItems":"3","DsItems":"oi"}
]
}
更新到数组,如果出现错误或
,这将有效<div data-bind='foreach: Items.Item'>
<span data-bind='text: DsItems'></span>
</div>