[英]How to display number of item in Ember.js template?
我可以像这样显示来自对象的数据:
<ul>
{{#each people}}
<li>Hello, {{name}}!</li>
{{/each}}
</ul>
但我想要添加这样的记录号:
<ul>
{{#each people}}
{{NUMBER_OF_PERSON}} <li>Hello, {{name}}!</li>
{{/each}}
</ul>
这个怎么做?
我假设你的意思是显示索引。 目前,您需要使用车把助手。 这个要点显示了一个示例https://gist.github.com/burin/1048968滚动浏览评论看起来有几种方法。
Handlebars有@index和@key,但目前这些都可以使用emberjs。
在控制器中,您可以编写如下函数:
no_of_person: function(){
return this._parentView.contentIndex;
}.property('people')
在模板中, {{no_of_person}}
将显示记录的索引号。
希望这可以帮助!
您可以使用CSS计数器 。 它也适用于表格。 以下是从MDN获取的示例:
ul { counter-reset: section; /* Creates a new instance of the section counter with each ol element */ list-style-type: none; } li:before { counter-increment: section; /* Increments only this instance of the section counter */ content: counters(section,".") " "; /* Adds the value of all instances of the section counter separated by a ".". */ }
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.