我在使用 Windows 8 应用程序在数组中显示信息时遇到问题,我用这个将信息发送到视图。
var details = document.querySelector(".articlesection");
var data = [{
"id": "1",
"title": "Title text",
"files": [
{
"id": "1",
"title": "File1"
},
{
"id": "2",
"title": "File2"
}
]
}];
binding.processAll(details, data);
我像这样在视图中接收数据(这有效,但无法从文件数组中获取信息)
<div class="articlesection">
<h2 data-win-bind="textContent: title">
<!-- Displays 1 -->
</h2>
<h3 data-win-bind="textContent: id">
<!-- Displays "Title text" -->
</h3>
</div>
我怎样才能让它显示数组中的 2 个对象?如果我尝试
<div class="articlesection">
<h2 data-win-bind="textContent: title">
<!-- Displays 1 -->
</h2>
<h3 data-win-bind="textContent: id">
<!-- Displays "Title text" -->
</h3>
<p data-win-bind="textContent: files">
<!-- i get [Object object], [Object object] -->
</p>
</div>
很明显,这里有一些数据,所以如果我想要这样的话,我该怎么做。(Foreach 不存在,但我想展示我想怎么做)
<div class="articlesection">
<h2 data-win-bind="textContent: title">
<!-- Displays 1 -->
</h2>
<h3 data-win-bind="textContent: id">
<!-- Displays "Title text" -->
</h3>
<ul data-win-bind: foreach: files>
<!-- Foreach all files, how can I do this? Foreach doesn't exist. -->
<li>
<span data-win-bind="textContent: id"></span>
<span data-win-bind="textContent: title"></span>
</li>
</ul>
</div>
问候,吉姆