Arb*_*æde 4 javascript knockout.js
您好我需要构建动态表,其中包含来自数组的列(标题)和来自其他数组的行,数组中的第一列必须是静态的.
<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>
Run Code Online (Sandbox Code Playgroud)
我有下一个Knockout HTML模型allRoles这是带有动态标头的数组
<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>
Run Code Online (Sandbox Code Playgroud)
我怎么能添加静态?
您可能正在寻找Knockout 的无容器控制流语法.它看起来像这样:
<table>
<thead>
<tr>
<th>Static</th>
<!-- ko foreach: allRoles -->
<th data-bind="text: name"></th>
<!-- /ko -->
</tr>
</thead>
</table>
Run Code Online (Sandbox Code Playgroud)
请参见注释4:http://knockoutjs.com/documentation/foreach-binding.html
| 归档时间: |
|
| 查看次数: |
4137 次 |
| 最近记录: |