因此,我发现阵列元素 可以用手持栏访问 使用:
{{myArray.2.nestedObject}} and {{myArray.0.nestedObject}}
(handlebars-access-array-items )
Is there a way to get the last element from an array? I tried creating a helper for it:
Handlebars.registerHelper("lastElement", function(array) {
return array.last(); //Array.prototype extension
});
...在模板中称它如下:
{{lastElement myArray}} or even {{lastElement myArray.lastElement nestedArray}}
可悲的是,这不起作用。 助手的函数显然返回字符串。 我需要的是能够做到这一点的方法, 即使是多维的阵列。