如何在 Polymer 1.0 中重新加载/刷新铁列表?

How to reload / refresh an iron-list in Polymer 1.0?

我已将一个项目添加到我的 数据 属性 绑定到 iron-list.

this.data.push(item); // add new item to array

现在已添加 data 项目,但列表不会刷新/重新加载以显示添加到 data 数组的新项目。你如何重新加载铁名单?似乎也无法在 iron-list API page 上找到方法。我尝试了以下但没有快乐...

var list = this.querySelector("iron-list");
list.fire('refresh');
list._refresh();

我的数据属性定义如下:

Polymer({
  is: "page-list",
  properties: {
    data: {
      type: Array,
      notify: true
    }

模板结构为:

<iron-ajax url="./data.json" last-response="{{data}}" auto></iron-ajax>
<iron-list items="[[data]]" as="item" class="fit">
  <template>
    <div class="row">
      <p>[[item.name]]</p>
    </div>
  </template>
</iron-list>

您将需要使用 Polymer 函数来添加新项目,例如 -

this.push('data', item);

Mutations to the items array itself (push, pop, splice, shift, unshift) must be performed using methods provided on Polymer elements, such that the changes are observable to any elements bound to the same array in the tree.

您可以从 here 阅读更多内容。