[英]Ractive.js template looping
I'm making an ajax call and pull down the total number of pages: 我正在进行ajax调用并拉下总页数:
$.get(path, function( data ) {
ractive.set({
'articles' : data.articles,
'totalpages' : data.totalpages
});
});
Is there any way I can render the pagination buttons from the total page count? 有什么办法可以从总页数中呈现分页按钮? Something like (assuming totalpages = 4):
类似于(假设总页数= 4):
{{#if loop totalpages times:num}}
<a href="#">{{num}}</a> |
{{/if}}
Would output 将输出
<a href="#">1</a> | <a href="#">2</a> | <a href="#">3</a> | <a href="#">4</a>
I had a look at Mustache docs, but Mustache isn't quite the same. 我看了一下Mustache文档,但是Mustache不太一样。
Thanks, Rob 谢谢,罗伯
Use a computed property in your component or ractive instance: 在组件或Ractive实例中使用计算属性:
computed: {
total: 'new Array(${totalPages})'
}
And then use the :index
(or whatever you want) to alias the index on the each: 然后使用
:index
(或您想要的任何值)为每个索引的别名:
{{#each total:index}}
<a href="#">{{index+1}}</a>
{{/each}}
Edit : Above total
computed property is Ractive shorthand for: 编辑 :上面的
total
计算属性是Ractive的简写:
computed: {
total: function(){
return new Array(this.get('totalPages'));
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.