聚合物dom-repeat不显示动态添加的值

时间:2017-03-23 15:05:50

标签: polymer dom-repeat

当我向动态添加一个新元素时,聚合物dom-repeat没有按预期工作,dom-repeat没有显示该值。

在将项目推入数组时,我正在使用Polymer的阵列变异方法,但仍无效。

请检查codepen链接;

    <dom-module id="wind-studio-widget">
  <template>
    <div on-tap='_addNewPad' style="cursor:pointer"><strong>Click Me</strong></div>
  <template id="padListContainerId" is="dom-repeat" items="[[padList]]">
    <p style="border:1px solid red">&nbsp;<span>[[item.id]]</span></p>
  </template>
  </template>
</dom-module>
<script type="text/javascript">
    Polymer({

        is: 'wind-studio-widget',

        properties: {
            baseUrl: {type: String},
            padList: {
                type: Array,
                notify: true
            },
            padListAverage: {type: Object}
        },

        ready: function () {
            //this.baseUrl = localStorage.baseUrl;
            //this.loadPadData();
          this.padList = [{'id':'1'},{'id':'2'}];
        },

        _addNewPad: function () {
            var newPadList = this.padList;
            newPadList.push({'id':'3'});
            this.set('padList', []);
            this.set('padList', newPadList);
            console.log(this.padList);
          //this.$.padListContainerId.render();
        }
    });
  </script>

http://codepen.io/nareshchennuri/pen/vxjvdO

0 个答案:

没有答案