javascript – 敲定’绑定’

前端之家收集整理的这篇文章主要介绍了javascript – 敲定’绑定’前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
原始问题

有没有人知道或者知道一个绑定的敲门,这将允许类似于for循环的行为?我可以做一个foreach做我想要的,但如果我不必这样做,这将是很好.

编辑2

我正在根据用户所做的选择来创建表行.在某些情况下,我需要x行,其中x是数组的长度,其他x代表显示n个数组所需的最大行数.

例如:image1是基于4个不同的数组构成的,所有的数组都有不同的大小
image2是从同一个数组构建的,在这种情况下翻倍.

@H_403_11@<div data-bind="if: selectedTab()"> <table> <thead> <tr> <td> <div class="a-i-post-All"></div> </td> <!-- ko foreach:$root.selectedTab().races--> <td> <input type="checkBox" /> </td> <!-- /ko --> </tr> </thead> <tbody data-bind="foreach: selectedTab().runners"> // <-- This is an empty array created by the max number of Runners in the selectedTabs array of Races <tr> <td> <div class="a-i-post"></div> </td> <!-- ko foreach:$root.selectedTab().races--> <td> <!-- ko if: Runners.length > $parentContext.$index()--> <input type="checkBox" /> <!-- /ko --> </td> <!-- /ko --> </tr> </tbody>

上面的工作正常,并创建了我想要的,但我不喜欢将selectedTab.runners从一个数字转换成一个空数组,只是为了使它循环n次创建行.我是开放的建议.注意在我刚刚发布这个问题的时候,我已经修改了这个代码,现在只有一个与我最初的问题相关的事情.

解决方法

我的 Repeat绑定完全是这样的. @H_403_11@<tbody> <tr data-bind="repeat: { foreach: selectedTab().runners,index: '$runner' }"> <td> <div class="a-i-post"></div> </td> <td data-bind="repeat: selectedTab().races"> <!-- ko if: $item().Runners.length > $runner --> <input type="checkBox" /> <!-- /ko --> </td> </tr> </tbody>

猜你在找的JavaScript相关文章