Polymer dom-repeat how to notify array updated

主宰稳场 提交于 2019-12-22 08:20:32

问题


So I have this Polymer element with dom-repeat. It binds correctly. However, when the array is modified, it doesn't reflect back to DOM. Nothing changed when I click on the button.

<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>

Is there a method like notifyArrayUpdated to tell the DOM to update binding data?


回答1:


When you change a subproperty inside an array, you need to do

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

Check out array binding for details.

Here is a plunker for it.



来源:https://stackoverflow.com/questions/32081221/polymer-dom-repeat-how-to-notify-array-updated

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!