要呼叫的阵列的特定项/对象在车把,使用
{{objects.[1].someAttribute}}
访问所述阵列中的第二对象的someAttribute
属性。
例如, http://emberjs.jsbin.com/xagewugi/1/edit
HBS
<script type="text/x-handlebars" data-template-name="index">
using <b>\{{each}}</b> helper
<ul>
{{#each item in model}}
<li>id: {{item.id}}<br/>
someAttr1: {{item.someAttr1}}</li>
{{/each}}
</ul>
calling an object <b>directly</b><br/>
this is the first object's attributes:<br/>
id: {{model.[0].id}}<br/>
someAttr1: {{model.[0].someAttr1}}
</script>
JS
App.IndexRoute = Ember.Route.extend({
model: function() {
return [
Em.Object.create({id:1,someAttr1:"attribute of 1"}),
Em.Object.create({id:2,someAttr1:"attribute of 2"}),
Em.Object.create({id:3,someAttr1:"attribute of 3"}),
Em.Object.create({id:4,someAttr1:"attribute of 4"})
];
}
});
还检查了这个How do I access an access array item by index in handlebars?
是否是对象数组?或者是范围应该是一个数组,我不知道我们从哪里获得第三个对象。 – Kingpin2k
感谢您的输入!我已经更新了这个问题要更加清楚。我希望如此帮助。 –