在Aurelia中,可以在重复中使用插槽来进行绑定吗? [英] In Aurelia, can a slot be used in a repeat.for binding?
问题描述
我想创建一个遍历数组的自定义元素,并将其应用于数组中的每个项目.例如,自定义元素的视图模板将包含以下内容:
I'd like to create a custom element that loops through an array and applies the to each item in the array. For example, the view template of the custom element would contain something like:
<div repeat.for="i of items">
<div with.bind="i">
<slot></slot>
</div>
</div>
当我删除repeat.for和with.bind属性时,广告位显示一次.有没有一种方法可以使列表中的每个项目重复进行此操作?
When I remove the repeat.for and with.bind attributes, the slot displays a single time. Is there a way to make it repeat for each item in the list?
推荐答案
否,您今天不能将插槽与repeat.for
或bind
一起使用.为此,您必须使用可更换的零件.例如:
No, you cannot use slots with repeat.for
or bind
today. To do this you have to use replaceable parts. For example:
<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中,可以在重复中使用插槽来进行绑定吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!