[英]Polymer: Two Way Binding to a Child Element Inside a Dom-Repeat Template
[英]Polymer <dom-repeat> data binding to child element not working?
我有一個如下的片段來嘗試將屬性向下傳遞給子元素,如下所示:
<dom-repeat items="{{employees}}" as="employee">
<template>
<child-element employee={{employee}}> </child-element>
</template>
</dom-repeat>
其中員工是數組類型(取自 Polymer 教程)。
employees: {
type: Array,
notify: true,
value() {
return [
{first: 'Bob', last: 'Smith'},
{first: 'Sally', last: 'Johnson'},
];
}
在我的子元素中,我只是試圖打印出傳遞下來的屬性:
<div> <span> {{employee}} </span> </div>
其中雇員被定義為
employee: {
type: String,
notify: true,
value: "",
},
但是,當我嘗試將它們打印出來時,這些值不會被傳遞。 如果我將員工的值更改為其他值,它就會被打印出來。 這是為什么? 我無法弄清楚為什么該屬性沒有被傳遞?
謝謝你。
事實證明它確實有效。 問題可能是將整個 object 傳遞給子元素。 改為只傳遞字符串:
<child-element employee={{employee.first}}> </child-element>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.