Polymer2.0 - dom-重复在纸标签内不起作用
Polymer2.0 - dom-repeat is not working inside paper-tabs
当我尝试在纸标签中包含 dom-repeat 时,我得到的是空白显示而不是 dom-repeat 值
DOM-重复在纸标签外工作正常但在纸标签内
Codepen- https://codepen.io/nagasai/pen/gxPQqQ
HTML:
<head>
<base href="https://polygit.org/polymer+v2.0.0/shadycss+webcomponents+1.0.0/components/">
<link rel="import" href="polymer/polymer.html">
<link rel="import" href="paper-tabs/paper-tabs.html">
<link rel="import" href="paper-tabs/paper-tab.html">
<link rel="import" href="iron-pages/iron-pages.html">
</head>
<body>
<x-custom></x-custom>
<dom-module id="x-custom">
<template>
<template is="dom-repeat" items="{{employees}}">
<div class="test">
<div># [[index]]</div>
<div>First name: <span>[[item.first]]</span></div>
<div>Last name: <span>[[item.last]]</span></div>
<div><img src="[[item.image]]" width="50px"></div>
</div>
</template>
</template>
<dom-bind><template>
<paper-tabs selected="{{selected}}" attr-for-selected="tab-name" fallback-selection="ui">
<paper-tab tab-name="ui">Grid</paper-tab>
<paper-tab tab-name="table">Table</paper-tab>
</paper-tabs>
<iron-pages selected="{{selected}}" attr-for-selected="tab-name" fallback-selection="ui" class="mainSection">
<div tab-name="ui">
<template>
<template is="dom-repeat" items="{{employees}}">
<div class="test">
<div># [[index]]</div>
<div>First name: <span>[[item.first]]</span></div>
<div>Last name: <span>[[item.last]]</span></div>
<div><img src="[[item.image]]" width="50px"></div>
</div>
</template>
</template>
</div>
<div tab-name="table">
Table
</div>
</iron-pages>
</template>
</dom-bind>
</dom-module>
JS:
class XCustom extends Polymer.Element {
static get is() { return 'x-custom'; }
static get properties() {
return {
employees: {
type: Array,
value() {
return [
{first: 'Bob', last: 'Smith',image:'https://dummyimage.com/300.png/09f/fff'},
{first: 'Adam', last: 'Gilchrist',image:'https://cdn.pixabay.com/photo/2015/03/04/22/35/head-659652_960_720.png'},
{first: 'Sally', last: 'Johnson'},
];
}
}
}
}
}
customElements.define(XCustom.is, XCustom);
代码笔:https://codepen.io/Sahero/pen/RZrvPN?editors=1111
HTML:
<head>
<base href="https://polygit.org/polymer+v2.0.0/shadycss+webcomponents+1.0.0/components/">
<link rel="import" href="polymer/polymer.html">
<link rel="import" href="paper-tabs/paper-tabs.html">
<link rel="import" href="paper-tabs/paper-tab.html">
<link rel="import" href="iron-pages/iron-pages.html">
</head>
<body>
<x-custom></x-custom>
<dom-module id="x-custom">
<template>
<dom-repeat items="{{employees}}">
<template>
<div class="test">
<div># [[index]]</div>
<div>First name: <span>[[item.first]]</span></div>
<div>Last name: <span>[[item.last]]</span></div>
<div><img src="[[item.image]]" width="50px"></div>
</div>
</template>
</dom-repeat>
<paper-tabs selected="{{selected}}" attr-for-selected="tab-name" fallback-selection="ui">
<paper-tab tab-name="ui">Grid</paper-tab>
<paper-tab tab-name="table">Table</paper-tab>
</paper-tabs>
<iron-pages selected="{{selected}}" attr-for-selected="tab-name" fallback-selection="ui" class="mainSection">
<div tab-name="ui">
<dom-repeat items="{{employees}}">
<template>
<div class="test">
<div># [[index]]</div>
<div>First name: <span>[[item.first]]</span></div>
<div>Last name: <span>[[item.last]]</span></div>
<div><img src="[[item.image]]" width="50px"></div>
</div>
</template>
</dom-repeat>
</div>
<div tab-name="table">
Table
</div>
</iron-pages>
</template>
</dom-module>
删除了 <dom-bind>
并更改了 </dom-module>
上方第一个 <template>
的结束标记。
JS:
同上。
当我尝试在纸标签中包含 dom-repeat 时,我得到的是空白显示而不是 dom-repeat 值
DOM-重复在纸标签外工作正常但在纸标签内
Codepen- https://codepen.io/nagasai/pen/gxPQqQ
HTML:
<head>
<base href="https://polygit.org/polymer+v2.0.0/shadycss+webcomponents+1.0.0/components/">
<link rel="import" href="polymer/polymer.html">
<link rel="import" href="paper-tabs/paper-tabs.html">
<link rel="import" href="paper-tabs/paper-tab.html">
<link rel="import" href="iron-pages/iron-pages.html">
</head>
<body>
<x-custom></x-custom>
<dom-module id="x-custom">
<template>
<template is="dom-repeat" items="{{employees}}">
<div class="test">
<div># [[index]]</div>
<div>First name: <span>[[item.first]]</span></div>
<div>Last name: <span>[[item.last]]</span></div>
<div><img src="[[item.image]]" width="50px"></div>
</div>
</template>
</template>
<dom-bind><template>
<paper-tabs selected="{{selected}}" attr-for-selected="tab-name" fallback-selection="ui">
<paper-tab tab-name="ui">Grid</paper-tab>
<paper-tab tab-name="table">Table</paper-tab>
</paper-tabs>
<iron-pages selected="{{selected}}" attr-for-selected="tab-name" fallback-selection="ui" class="mainSection">
<div tab-name="ui">
<template>
<template is="dom-repeat" items="{{employees}}">
<div class="test">
<div># [[index]]</div>
<div>First name: <span>[[item.first]]</span></div>
<div>Last name: <span>[[item.last]]</span></div>
<div><img src="[[item.image]]" width="50px"></div>
</div>
</template>
</template>
</div>
<div tab-name="table">
Table
</div>
</iron-pages>
</template>
</dom-bind>
</dom-module>
JS:
class XCustom extends Polymer.Element {
static get is() { return 'x-custom'; }
static get properties() {
return {
employees: {
type: Array,
value() {
return [
{first: 'Bob', last: 'Smith',image:'https://dummyimage.com/300.png/09f/fff'},
{first: 'Adam', last: 'Gilchrist',image:'https://cdn.pixabay.com/photo/2015/03/04/22/35/head-659652_960_720.png'},
{first: 'Sally', last: 'Johnson'},
];
}
}
}
}
}
customElements.define(XCustom.is, XCustom);
代码笔:https://codepen.io/Sahero/pen/RZrvPN?editors=1111
HTML:
<head>
<base href="https://polygit.org/polymer+v2.0.0/shadycss+webcomponents+1.0.0/components/">
<link rel="import" href="polymer/polymer.html">
<link rel="import" href="paper-tabs/paper-tabs.html">
<link rel="import" href="paper-tabs/paper-tab.html">
<link rel="import" href="iron-pages/iron-pages.html">
</head>
<body>
<x-custom></x-custom>
<dom-module id="x-custom">
<template>
<dom-repeat items="{{employees}}">
<template>
<div class="test">
<div># [[index]]</div>
<div>First name: <span>[[item.first]]</span></div>
<div>Last name: <span>[[item.last]]</span></div>
<div><img src="[[item.image]]" width="50px"></div>
</div>
</template>
</dom-repeat>
<paper-tabs selected="{{selected}}" attr-for-selected="tab-name" fallback-selection="ui">
<paper-tab tab-name="ui">Grid</paper-tab>
<paper-tab tab-name="table">Table</paper-tab>
</paper-tabs>
<iron-pages selected="{{selected}}" attr-for-selected="tab-name" fallback-selection="ui" class="mainSection">
<div tab-name="ui">
<dom-repeat items="{{employees}}">
<template>
<div class="test">
<div># [[index]]</div>
<div>First name: <span>[[item.first]]</span></div>
<div>Last name: <span>[[item.last]]</span></div>
<div><img src="[[item.image]]" width="50px"></div>
</div>
</template>
</dom-repeat>
</div>
<div tab-name="table">
Table
</div>
</iron-pages>
</template>
</dom-module>
删除了 <dom-bind>
并更改了 </dom-module>
上方第一个 <template>
的结束标记。
JS: 同上。