我想将data.js文件中的javascript数组转换为ko.observable数组并将其绑定到列表标签
的HTML
<script type="text/html" id="profileListTemplate">
<li>
<strong data-bind="text: name"></strong>
</li>
</script>
<h1>Profile Viewer</h1>
<div class="tabbable tabs-left" id="profilesTabViewer">
<ul class="nav nav-tabs" id="profileTab" data-bind="template: { name: 'profileListTemplate'}">
</ul>
<div class="tab-content" id="profileContent">
</div>
</div>`
Run Code Online (Sandbox Code Playgroud)
var data = [
{
'id': '1',
'firstName': 'Megan',
'lastName': 'Fox',
'picture': 'images/01.jpg',
'bio': 'Megan Denise Fox was born May 16, 1986 in Rockwood, Tennessee. ...
},
....
];
Run Code Online (Sandbox Code Playgroud)
小智 5
干净利落:
var myObservableArray = ko.observableArray(data);
Run Code Online (Sandbox Code Playgroud)
这是您更新的JSFiddle:http : //jsfiddle.net/simonlevasseur/qr7PL/
请注意,在模板中,您不应放置:people.firstName,它应该只是firstName,如此处所述:http ://knockoutjs.com/documentation/foreach-binding.html
| 归档时间: |
|
| 查看次数: |
7545 次 |
| 最近记录: |