我想创建一个自定义元素,该元素循环遍历数组并将其应用于数组中的每个项目。例如,自定义元素的 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/