[英]Ractive.js template looping
我正在進行ajax調用並拉下總頁數:
$.get(path, function( data ) {
ractive.set({
'articles' : data.articles,
'totalpages' : data.totalpages
});
});
有什么辦法可以從總頁數中呈現分頁按鈕? 類似於(假設總頁數= 4):
{{#if loop totalpages times:num}}
<a href="#">{{num}}</a> |
{{/if}}
將輸出
<a href="#">1</a> | <a href="#">2</a> | <a href="#">3</a> | <a href="#">4</a>
我看了一下Mustache文檔,但是Mustache不太一樣。
謝謝,羅伯
在組件或Ractive實例中使用計算屬性:
computed: {
total: 'new Array(${totalPages})'
}
然后使用:index
(或您想要的任何值)為每個索引的別名:
{{#each total:index}}
<a href="#">{{index+1}}</a>
{{/each}}
編輯 :上面的total
計算屬性是Ractive的簡寫:
computed: {
total: function(){
return new Array(this.get('totalPages'));
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.