Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/375.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ember.js/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 使用{render}进行渲染时的循环计数器_Javascript_Ember.js_Handlebars.js - Fatal编程技术网

Javascript 使用{render}进行渲染时的循环计数器

Javascript 使用{render}进行渲染时的循环计数器,javascript,ember.js,handlebars.js,Javascript,Ember.js,Handlebars.js,我有一个在循环中呈现的帖子列表 {{#each post in posts}} {{render "post" post}} {{/each}} 现在,在post模板中,我想访问post的索引,以便输出“post 1”、“post 2”等等。我怎样才能做到这一点 我尝试从每个PostView访问contentIndex,但该属性为空。在您的post模板中,您可以使用{{{u view.\u parentView.contentIndex}}访问索引,它是零相对的。我喜欢这个样品 另一种选择

我有一个在循环中呈现的帖子列表

{{#each post in posts}}
  {{render "post" post}}
{{/each}}
现在,在
post
模板中,我想访问post的索引,以便输出“post 1”、“post 2”等等。我怎样才能做到这一点


我尝试从每个
PostView
访问
contentIndex
,但该属性为空。

在您的post模板中,您可以使用
{{{u view.\u parentView.contentIndex}}
访问索引,它是零相对的。我喜欢这个样品

另一种选择是将帖子内容包装到带有索引的新对象中。像这样