繁体   English   中英

灰烬在模板中传递多个列表项

[英]Ember passing multiple list items in template

是否可以使用{{each}}传递模板中的多个项目列表

有人可以指导我我在做什么,在下面的sales-orders.hbs中是我的currenet代码。

    {{#each model as |detail|}}
        <li>{{sales-orders-grid detail=detail}}</li>
    {{else}}
      Blank
    {{/each}}
    </ul>

然后调用sales-orders-grid组件

Shipping Method
      <div class="col-xs-12 col-md-12 col-sm-12 products-item-products border-left padding10">
        <ul>
            {{#each shippingMethod as |sm|}}
                {{sales-orders-grid-shipping-method sm=sm}}
            {{/each}}
        </ul>
      </div>

在我的sales-orders-grid-shipping-method组件中,调用是这样的:

sm.shippingMethodName

我要在这里实现的是在主模板的{{each}}中传递项目列表。 可能吗?

要更改范围,可以使用“ with”帮助器。

http://emberjs.com/api/classes/Ember.Templates.helpers.html#method_with

{{#with user.posts as |blogPosts|}}
  <div class="notice">
    There are {{blogPosts.length}} blog posts written by {{user.name}}.
  </div>
  {{#each blogPosts as |post|}}
    <li>{{post.title}}</li>
  {{/each}}
{{/with}}

我认为您可以嵌套多个“带有”帮助器。

我认为方法是将数据重构为:model.list1,model.list2等。 然后传递模型并根据需要使用它,并使用嵌套的每个实现网格。 Iam仅将此发布为答案,因为我还不能发表评论。 因此,请务必回覆我。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM