用句柄渲染一个字符串数组 [英] Rendering a string array with handlebars
本文介绍了用句柄渲染一个字符串数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
可以说我在这个ember控制器中有一个这样的数组,
Lets say I have an array like this in ember controller,
selectedUsers: ["Popeye", "Sulley", "Gru"];
现在,我该如何渲染每个用户在使用把手的无序列表中?我可以使用 {{#Each}}
helper吗?
Now, how can i render each users in an unordered list using handlebars? Can i use the {{#Each}}
helper?
推荐答案
是的,您应该使用每个
循环:
Yes, you should use an each
loop:
<ul>
{{#each selectedUsers}}
<li>{{ this }}</li>
{{/each}}
</ul>
从文档:
$ b
From the docs:
您可以使用内置的
来遍历列表,每个
helper。在块内部,您可以使用this
引用正在迭代的元素。
You can iterate over a list using the built-in
each
helper. Inside the block, you can usethis
to reference the element being iterated over.
<ul class="people_list">
{{#each people}}
<li>{{this}}</li>
{{/each}}
</ul>
在使用此上下文时:
when used with this context:
{
people: [
"Yehuda Katz",
"Alan Johnson",
"Charles Jolley"
]
}
会导致:
will result in:
<ul class="people_list">
<li>Yehuda Katz</li>
<li>Alan Johnson</li>
<li>Charles Jolley</li>
</ul>
您可以在任何上下文中使用此表达式来引用当前上下文。
You can use the this expression in any context to reference the current context.
这篇关于用句柄渲染一个字符串数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文