[英]Ember Octane - How to loop through model records inside a component?
I have an array of strings passed as an argument to a component, inside the component I am using "each" helper to render each string in a text input.我有一个字符串数组作为参数传递给组件,在组件内部我使用“每个”帮助器来呈现文本输入中的每个字符串。 I tried the following approach.
我尝试了以下方法。
I have a model passed as an argument to a component.我有一个 model 作为参数传递给组件。 I'm using #each helper to iterate through that model and this does not work.
我正在使用#each helper 遍历该 model 但这不起作用。
Example:例子:
<div>
<Location::LocationList @model="{{@model}}"/>
</div>
<ul class="location-list">
{{#each this.args.model as |location|}}
<li>
{{@location.title}}
</li>
{{/each}}
</ul>
And if I just do it in this way:如果我只是这样做:
<ul class="location-list">
{{#each @model as |location|}}
<li>
<Location::LocationItem @location={{location}}/>
</li>
{{/each}}
</ul>
It works as needed.它根据需要工作。 Any suggestions?
有什么建议么?
According to the docs on Component Arguments , using the @model
as you have in your last snippet,根据Component Arguments上的文档,使用上一个片段中的
@model
,
<ul class="location-list">
{{#each @model as |location|}}
<li>
<Location::LocationItem @location={{location}}/>
</li>
{{/each}}
</ul>
is the correct way to reference arguments.是引用 arguments 的正确方法。
Referencing args via this.args
is reserved for usage in the class body of a component.通过
this.args
引用 args 保留用于组件的 class 主体。
the @namedArgs
syntax is consistent across class-based components and template-only components as template-only components do not have a this
. @namedArgs
语法在基于类的组件和仅模板组件之间是一致的,因为仅模板组件没有this
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.