gpt4 book ai didi

javascript - 如何 dom-repeat 槽内容

转载 作者:行者123 更新时间:2023-12-03 01:56:20 25 4
gpt4 key购买 nike

我正在尝试创建一个可重用列表,将其行模板作为插槽传入,但插槽内容仅重复一次。示例如下:https://codepen.io/chris-gunawardena/project/editor/XkPYQw

<script src="https://polygit.org/components/webcomponentsjs/webcomponents-lite.js"></script>
<link rel="import" href="https://polygit.org/components/paper-button/paper-button.html">
<dom-module id="list-repeater">
<template>
<template is="dom-repeat" items="{{items}}" as="item">
<li>
# [[index]]: [[item]] <slot name="row-template"></slot>
</li>
</template>
</template>
<script>
class ListRepeater extends Polymer.Element {
static get is() {
return 'list-repeater';
}
static get properties() {
return {
items: Array,
};
}
}
customElements.define(ListRepeater.is, ListRepeater);
</script>
</dom-module>

它的使用方式如下:

  <list-repeater items='["a","b"]'>
<div slot="row-template">--slot content--</div>
</list-repeater>

该功能类似于iron-list,它接受模板,但很难理解iron-list正在做什么。

最佳答案

在您的情况下,使用插槽不起作用,iron-list 正在使用 Templatizer Behavior为了实现这个目标

The Polymer.Templatizer behavior adds methods to generate instances of templates that are each managed by an anonymous Polymer.PropertyEffects instance where data-bindings in the stamped template content are bound to accessors on itself.

关于javascript - 如何 dom-repeat 槽内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50212313/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com