数组的淘汰赛 [英] Knockout array of arrays
本文介绍了数组的淘汰赛的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
传入的数据就像这样的[[1,2,3],[4,5,6]]
,有时也像这样的[[1,2],[4,5]]
.这是HTML.
The incomming data is like this [[1,2,3],[4,5,6]]
and sometimes it is like this [[1,2],[4,5]]
. Here is the HTML.
<button data-bind="click: refreshJSON">Test</button>
<table>
<tbody data-bind="foreach: array">
<tr data-bind="foreach: subarray">
<td data-bind="text: $data"></td>
</tr>
</tbody>
</table>
<script type="text/javascript">
var ViewModel = {
tableModel : ko.observableArray([[1,2,3],[4,5,6]]),
refreshJSON : function(){
this.tableModel([[1,2],[4,5]]);
}
};
ko.applyBindings(ViewModel);
</script>
我猜我必须在每个子数组上使用ko.observableArray()
,但是我不清楚如何执行此操作,或者如何在HTML中执行data-binds
.
I'm guessing I have to use ko.observableArray()
on each of the subarrays however I'm unclear on how to do this, or how to do the data-binds
in the HTML.
推荐答案
更新:删除了observableArray位内的observableArray.显然这是行不通的.只需绑定您的外部收藏即可.
Update: Removed the observableArray inside an observableArray bit. Apparently that doesn't work. Just bind your outer collection.
绑定部分非常简单:
<div data-bind="foreach: tableModel">
<div data-bind="foreach: $data">
<span data-bind="text: $data"></span>
</div>
</div>
这篇关于数组的淘汰赛的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文