gpt4 book ai didi

javascript - knockout 如何在 foreach 期间将自定义列添加到表

转载 作者:搜寻专家 更新时间:2023-11-01 05:12:55 24 4
gpt4 key购买 nike

你好,我需要用数组中的列(标题)和其他数组中的行构建动态表,数组中的第一列必须是静态的。

<table>
<thead>
<tr>
<th>Static</th>
<th>Dynamic 1</th>
<th>Dynamic 2</th>
<th>Dynamic 3</th>
</tr>
</thead>
<tbody>
<tr>
<th>Nam1</th>
<th>value</th>
<th>value</th>
<th>value</th>
</tr>
</tbody>
</table>

我有下一个 Knockout HTML 模型 allRoles 这是带有动态 header 的数组

<table>
<thead>
<tr data-bind="template: { name: 'tableHeader', foreach: allRoles, as: 'role',afterRender: addFirstColumn } ">

</tr>
</thead>
<tbody data-bind="foreach: {data: userRoles,as:'dep'}">
<tr>
<td>
<span data-bind="text: dep.name"></span>
</td>
<td data-bind="foreach: {data: dep.roles, as: 'role'}">
<span data-bind="text: role.id"></span>
</td>
</tr>
</tbody>
</table>


<script type="text/html" id="tableHeader">
<th data-bind="text: role.name">

</th>
</script>

如何添加静态?

最佳答案

您可能正在寻找 Knockout 的无容器控制流语法。它看起来像这样:

<table>
<thead>
<tr>
<th>Static</th>
<!-- ko foreach: allRoles -->
<th data-bind="text: name"></th>
<!-- /ko -->
</tr>
</thead>
</table>

请参阅此处的注释 4:http://knockoutjs.com/documentation/foreach-binding.html

关于javascript - knockout 如何在 foreach 期间将自定义列添加到表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16109081/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com