我有数据
data = [{
"task": "get milk",
"who": "Scott",
"done": false
}, {
"task": "get broccoli",
"who": "Elisabeth",
"done": false
}, {
"task": "get
garlic",
"who": "Trish",
"done": false
}, {
"task": "get
eggs",
"who": "Josh",
"done": true
}];
<ul>
<li data-each-[]="">
</li>
<ul>
我如何使用
在rivets.js中打印此数据答案 0 :(得分:1)
快捷方式:
<ul>
<li rv-each-data="item">
<dl>
<dt>Task:</dt><dd>{ item.task }</dd>
<dt>Who:</dt><dd>{ item.who}</dd>
<dt>Done:</dt><dd>{ item.done}</dd>
</dl>
</li>
</ul>
答案 1 :(得分:0)
我认为以下示例可以帮助您。
<ul id="playersList">
<li rv-each-player="players">
<dl>
<dt>Name:</dt><dd>{ player.name }</dd>
<dt>Surname:</dt><dd>{ player.surname }</dd>
<dt>Shirt Number:</dt><dd>{ player.number }</dd>
<!-- This element will be rendered only if this property will be set -->
<dd rv-if="player.captain"><b> Captain! </b></dd>
</dl>
</li>
</ul>
Javascript:
var soccerTeam = [{"number":1,"name":"Gianluigi","surname":"Buffon"},
{"number":19,"name":"Gianluca","surname":"Zambrotta"},
{"number":5,"name":"Fabio","surname":"Cannavaro","captain":true},
{"number":9,"name":"Luca","surname":"Toni"}];
// get the DOM elements
var playersList = document.getElementById('playersList');
// pass the data to the DOM element
rivets.bind(playersList,{players:soccerTeam});
此链接也可以帮助您: http://www.gianlucaguarini.com/blog/rivet-js-backbone-js-made-my-code-awesome/