聚合物dom-repeat如何通知数组更新

Polymer dom-repeat how to notify array updated

本文关键字:通知 数组 更新 dom-repeat 何通知 聚合物      更新时间:2023-09-26

所以我有这个dom-repeat的Polymer元素。它能正确地结合。但是,当数组被修改时,它不会反射回DOM。当我点击按钮时,什么都没有改变。

<dom-module id="my-element">
  <template>
    <template is="dom-repeat" id="allRules" items="{{allRules}}">
      <span class="tag" rule-enabled$={{item.enabled}}>{{item.name}}</span>
    </template>
    <button on-click="click">Click me</button>
  </template>
</dom-module>
<script>
  Polymer({
    is: "my-element",
    properties: {
      allRules: {
        type: Array,
        notify: true
      }
    },
    click: function() {
      this.allRules[0].name = "three";
    },
    ready: function() {
      this.allRules = [
        {
          name: "one",
          enabled: true
        }, {
          name: "two",
          enabled: false
        }
      ]
    },
    setBind: function(bind) {
      this.bind = bind;
    }
  });
</script>

是否有像notifyArrayUpdated这样的方法来告诉DOM更新绑定数据?

当您更改数组中的子属性时,您需要执行

this.set('allRules.0.name', 'three');

查看数组绑定的详细信息。