我无法在我的 javascript Metro 应用程序中绑定表,而不是与模板中提供的 html 绑定,它会放入大量 div 并将 json 呈现为字符串。这就是我所拥有的:
<tr id="tableRow" data-win-control="WinJS.Binding.Template">
<td data-win-bind="innerText: label"></td>
<td data-win-bind="innerText: value"></td>
<td></td>
</tr>
<table>
<thead>
<tr>
<th>col1</th>
<th>col2</th>
<th>col3</th>
</tr>
</thead>
<tbody class="topContent" data-win-control="WinJS.UI.ListView" data-win-options="{ selectionMode: 'none' }"></tbody>
</table>
我用来绑定的 javascript (topContent 是 { label, value} 对象的列表:
function bindContent() {
var list = new WinJS.Binding.List();
topContent.forEach(function (item) {
list.push(item);
});
var listView = document.querySelector(".topContent").winControl;
var template = document.getElementById("tableRow");
listView.layout = new ui.ListLayout();
listView.itemTemplate = template;
listView.itemDataSource = list.dataSource;
}