我試圖從<iron-list>
中的自定義聚合物組件<data-component>
輸出數據,但是當我打開該頁面時沒有顯示任何內容。它工作時,我直接傳遞一個對象的數組,如<iron-list items='[{"name": "test1"}, {"name":"test2"}]' >
聚合物:將屬性傳遞給子元素不起作用
我在做什麼錯在這裏,是<template is="dom-bind" id="t">
強制性的?
的index.html
<html>
<head>
<script src="../../webcomponentsjs/webcomponents-lite.js"></script>
<link rel="import" href="../data-component.html">
<link rel="import" href="../../iron-list/iron-list.html">
</head>
<body unresolved>
<template is="dom-bind" id="t">
<data-component>
<!--<iron-list items='[{"name": "test1"}, {"name":"test2"}]' > WORKS -->
<iron-list items="{{data}}" >
<template>
<div>
Name: <span>{{item.name}}</span>
</div>
</template>
</iron-list>
</data-component>
</template>
</body>
</html>
數據component.html
<link rel="import" href="../polymer/polymer.html">
<dom-module id="data-component">
<template>
<content></content>
</template>
</dom-module>
<script>
window.coolData = [
{"name": "Bob"},
{"name": "Tim"},
{"name": "Mike"}
];
Polymer({
is: 'data-component',
properties: {
data: {
value: window.coolData
}
}
});
</script>
你必須指定數據類型'的類型:Array' –
@PascalGula好點。我會將其添加到我的答案中。 – Maria
你是通過內容標籤插入'iron-list'還是你也可以放置在'data-component'的本地dom中?第二種方法可以讓你擺脫'dom-bind'。 – Maria