【问题标题】:Polymer <dom-repeat> data binding to child element not working?Polymer <dom-repeat> 数据绑定到子元素不起作用?
【发布时间】:2020-07-23 08:58:13
【问题描述】:

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

<dom-repeat items="{{employees}}" as="employee">
  <template>
    <child-element employee={{employee}}> </child-element> 
  </template>
</dom-repeat>

employee 是数组类型(取自 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: "",
},

但是,当我尝试打印这些值时,它们并没有传递下去。如果我将员工的值更改为其他值,它就会被打印出来。这是为什么?我无法弄清楚为什么该属性没有被传递?

谢谢。

【问题讨论】:

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


    【解决方案1】:

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

    <child-element employee={{employee.first}}> </child-element> 
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-08-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多