2

我有一个像下面这样的聚合物特性。

gamma:{type:Array,observe:true,notify:true,value: [{"id":1,"value":["w"]}, {"id":2,"value":["w "]}]}

我正在使用此属性使用 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。我正在从添加列方法调用渲染函数。

我有另一种称为 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

4

1 回答 1

0

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

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

所以你的定义应该是:

gamma: {
    type: Array,
    observe: true,
    notify: true,
    value: function () {
        return [{"id": 1, "value": ["w"]}, {"id": 2, "value": ["w"]}]
    }
}
于 2016-03-14T08:37:59.080 回答