聚合物<dom-repeat>数据绑定到子元素无效吗?

时间:2020-07-22 21:08:28

标签: polymer polymer-2.x polymer-3.x

我有一个摘录,尝试将属性向下传递给子元素,如下所示:

<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: "",
},

但是,当我尝试将它们打印出来时,这些值不会传递下来。如果我将员工的价值更改为其他价值,它将被打印出来。这是为什么?我不知道为什么该财产没有被传下来?

谢谢。

1 个答案:

答案 0 :(得分:0)

结果证明它确实有效。问题可能是将整个对象传递给子元素。更改为仅传递字符串:

<child-element employee={{employee.first}}> </child-element> 
相关问题