<dom-repeat> 中的聚合物子属性

Polymer sub-properties in <dom-repeat>

在 "dom-repeat" 上的聚合物文档中说:

Notifications for changes to items sub-properties are forwarded to the template instances, which update via the normal structured data notification system .

我认为这意味着如果我更改数组的一个元素,它将更新任何绑定元素。我认为情况并非如此。考虑到这一点,更新子属性的唯一选择似乎是使用数组方法或自定义函数重建数组,这对于更大的数据会越来越困难。或者以某种方式将观察者添加到所有子属性中,这感觉效率不高。有什么建议吗?

无效示例:http://jsbin.com/wadeju/1/edit?html,output

(function(){
  Polymer({
    is: 'x-element',
    properties:{
      d:{
        type: String,
        value:"Click Me"
      },
      days:{ 
        type: Array,
        value: ["one", "two", "three"]
      }
    },
    c:function(){
        this.days[0] = "1";
        this.days[1] = "2";
        this.days[2] = "3";
        this.d="hello";
     },
  });

有效示例:http://jsbin.com/luqudo/edit?html,output

Polymer({
        is: 'x-element',
        properties:{
          d:{
            type: String,
            value:"Click Me"
          },
          days:{ 
            type: Array,
            value: ["one", "two", "three"]
          }
        },
        c:function(){
            this.days = ["1", "2", "3"]
            this.d="hello";
         },
      });
    })();

绑定数组值的推荐方式:
https://www.polymer-project.org/1.0/docs/devguide/data-binding.html#array-binding

请注意,dom-repeat 示例还使用数组中的命名对象进行绑定。

您应该使用 Polymer 的(数组)变异方法来保持同步:
https://www.polymer-project.org/1.0/docs/devguide/properties.html#array-mutation

仅使用 Polymer 的 属性 突变设置数据的示例:
http://jsbin.com/zuhecovequ/1/edit?html,output

(function(){
  Polymer({
    is: 'x-element',
    properties:{
      d:{
        type: String,
        value:"Click Me"
      },
      days:{ 
        type: Array,
        value: ["one", "two", "three"]
      }
    },
    c:function(){
        this.set("days.0","1");
        this.set("days.1","2");
        this.set("days.2","3");
        this.d="hello";
     },
  });
})();