aurelia - 在 Aurelia 中,可以在 repeat.for 绑定(bind)中使用插槽吗?

标签 aurelia aurelia-templating

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

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

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

最佳答案

不,您不能将插槽与 repeat.for 一起使用或 bind今天。为此,您必须使用可更换部件。例如:

<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 中,可以在 repeat.for 绑定(bind)中使用插槽吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44402632/

相关文章:

javascript - Aurelia 绑定(bind)在样式复选框上

javascript - 获取客户端重定向

aurelia - 如何在不使用路由器的情况下强制 Aurelia 销毁/重新创建 View / View 模型对

javascript - 在 Aurelia 中动态加载内容后执行函数

javascript - 如何在 View 外评估 Aurelia 插值表达式?

aurelia - 是否可以在javascript中加载Aurelia模板并转换为字符串

javascript - Aurelia 绑定(bind)按钮回调函数

javascript - Aurelia show.bind 是否有回调或 promise ?

javascript - Aurelia 自定义元素 - $parent 未定义