代码之家  ›  专栏  ›  技术社区  ›  NeitoFR

聚合物2.5.0-dom重复未更新

  •  1
  • NeitoFR  · 技术社区  · 6 年前

    this post this other post

    <li> 到一个 <ul> 但是当我使用数组变异方法时,它不起作用(我可以正确地记录数组的更新)。

    我尝试使用JSON数组而不是简单的字符串,并尝试 this.notifyPath('peoples'); ,但仍然不起作用

    static get properties() {
        return {
            peoples: {
                type: Array,
                value: []
            }
        }
    }
    _test2() {
        console.log(this.peoples);
    
    }
    _test() {
        this.push('peoples', 'test');
    }
    <div class="flex__item--top list">
        <ul id="namelist">
            <template is="dom-repeat" items={{peoples}}>
                <li>{{item}}</li>
            </template>
        </ul>
    </div>
    1 回复  |  直到 6 年前
        1
  •  3
  •   Hyyan Abo Fakher JM1    6 年前

    你可以强迫 dom-repeat 通过调用 render 方法。

    render(): void

    强制元素呈现其内容。通常渲染是 与引起变化的不同步。这样做是为了提高效率 多次更改只触发一次渲染。渲染方法 例如,如果需要模板呈现 验证应用程序状态。

    所以如果你的 dom重复

    <template id="list" is="dom-repeat" items={{peoples}}>
                <li>{{item}}</li>
    </template>
    

    可以像这样从组件强制渲染

    _test() {
        this.push('peoples', 'test');
        this.$.list.render();
    }