[英]How to display number of item in Ember.js template?
I can display data from object like this: 我可以像这样显示来自对象的数据:
<ul>
{{#each people}}
<li>Hello, {{name}}!</li>
{{/each}}
</ul>
But i would want to add the number of the record like this: 但我想要添加这样的记录号:
<ul>
{{#each people}}
{{NUMBER_OF_PERSON}} <li>Hello, {{name}}!</li>
{{/each}}
</ul>
How to do this? 这个怎么做?
I'm going to assume you mean display an index. 我假设你的意思是显示索引。 Currently you need to use a handlebars helper.
目前,您需要使用车把助手。 This gist shows an example https://gist.github.com/burin/1048968 scrolling through the comments it looks like there are several approaches.
这个要点显示了一个示例https://gist.github.com/burin/1048968滚动浏览评论看起来有几种方法。
Handlebars has @index and @key, but currently these do now work with emberjs. Handlebars有@index和@key,但目前这些都可以使用emberjs。
In the controller, you can write a function like this: 在控制器中,您可以编写如下函数:
no_of_person: function(){
return this._parentView.contentIndex;
}.property('people')
In the template, {{no_of_person}}
will show the index number of the record. 在模板中,
{{no_of_person}}
将显示记录的索引号。
Hope this helps! 希望这可以帮助!
You can use CSS Counters . 您可以使用CSS计数器 。 It works for tables too.
它也适用于表格。 Here's an example taken from MDN:
以下是从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.