聚合物dom-repeat在阵列更新后无法更新

时间:2016-03-10 22:14:03

标签: arrays polymer repeat mutation

我有如下聚合物属性。

gamma:{type:Array,observe:true,notify:true,value:[{“id”:1,“value”:[“w”]},                                 { “ID”:2 “值”:[ “瓦特”]}]}

我正在使用此属性在div中显示模板中的行和列。

<template is="dom-repeat" items="{{gamma}}" id="maindiv">
            <div class="layout__row">
            <template is="dom-repeat" items="{{item.value}}">
                <div class="layout__block" id$="{{item}}">
                    <button class="btn btn--primary margins">Add {{item}}      Button</button>
                </div>
            </template>
            </div>
            </template>

如果我修改gamma属性以在第一个对象中添加一个值,并调用notifysplices,则不会根据数字呈现div。我从add columns方法调用render函数。

我有另一个名为addrows的方法,它有这个代码。

addRows: function(){
                    this.push("gamma", {"id":this.rows.length+1,"value":     ["w"]} );
                    this.$.maindiv.render();
                    this.$.rowdiv.render();
                }

我在这里失踪了。

我发现解决方案,子属性或嵌套数组更改应如下所示。

this.push([“gamma”,i,“value”],“a”);

感谢来自polymer.slack.com的Arthur Evans

1 个答案:

答案 0 :(得分:0)

gamma属性的定义可能导致问题。根据聚合物文档

  

如果默认值应该是实例唯一的数组或对象,请在函数内创建数组或对象。有关详细信息,请参阅Configuring default property values

所以你的定义应该是:

gamma: {
    type: Array,
    observe: true,
    notify: true,
    value: function () {
        return [{"id": 1, "value": ["w"]}, {"id": 2, "value": ["w"]}]
    }
}
相关问题