【问题标题】:In Aurelia, can a slot be used in a repeat.for binding?在 Aurelia 中,可以在 repeat.for 绑定中使用插槽吗?
【发布时间】:2018-02-04 23:40:04
【问题描述】:

我想创建一个自定义元素,该元素循环遍历数组并将 应用于数组中的每个项目。例如,自定义元素的视图模板将包含以下内容:

<div repeat.for="i of items">
  <div with.bind="i">
    <slot></slot>
  </div>
</div>

当我删除 repeat.for 和 with.bind 属性时,槽显示一次。有没有办法让它对列表中的每个项目重复?

【问题讨论】:

    标签: aurelia aurelia-templating


    【解决方案1】:

    不,您今天不能使用带有 repeat.forbind 的插槽。为此,您必须使用可更换部件。例如:

    <div repeat.for="i of items">
      <div with.bind="i">
        <template replaceable part="content"></template>
      </div>
    </div>
    

    用法:

    <my-component>
      <template replace-part="content">Some Content - ${somePropertyOfI}</template>
    </my-component>
    

    可运行示例:https://gist.run/?id=29aa1c1199f080c9ba0e72845044799b

    【讨论】:

    • aurelia 博客aurelia.io/blog/2016/05/23/… 说“以上所有内容都是用 Aurelia 实现的。它还可以与模板控制器一起使用,例如 if 和 repeat 可以动态生成内容。我们已经修复了我们的 @child 和@儿童装饰师也可以了解新模型。”但它似乎不起作用
    • @MosèBottacini 在回答此问题时,无法将“repeat”或bind&lt;slot&gt; 一起使用。告诉我你想做什么,我会尽力给你一个解决方案
    • 只是表示文档可能不同步,因为它明确指出可以完成
    猜你喜欢
    • 1970-01-01
    • 2021-05-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多