Gle*_*hes 4 aurelia aurelia-templating
我想创建一个循环遍历数组的自定义元素,并将其应用于数组中的每个项目.例如,自定义元素的视图模板将包含以下内容:
<div repeat.for="i of items">
<div with.bind="i">
<slot></slot>
</div>
</div>
Run Code Online (Sandbox Code Playgroud)
当我删除repeat.for和with.bind属性时,插槽显示一次.有没有办法让它重复列表中的每个项目?
不,你不能使用插槽repeat.for
或bind
今天.为此,您必须使用可更换部件.例如:
<div repeat.for="i of items">
<div with.bind="i">
<template replaceable part="content"></template>
</div>
</div>
Run Code Online (Sandbox Code Playgroud)
用法:
<my-component>
<template replace-part="content">Some Content - ${somePropertyOfI}</template>
</my-component>
Run Code Online (Sandbox Code Playgroud)
可运行的例子:https://gist.run/? id = 29aa1c1199f080c9ba0e72845044799b