聚合物绑定数组和计算的属性/绑定

时间:2015-11-18 07:06:20

标签: javascript data-binding polymer-1.0

我尝试了一个简单的示例:array bindingcomputed propertycomputed binding

<dom-module id="my-element">
    <template>
        <p>list of r: 
            <template is="dom-repeat" items="{{r}}">
                <span>{{item}}</span>,
            </template>
        <p>
        <p>computed property: {{length}}<p>
        <p>computed value: {{_length(r)}}<p>
        <button on-click='_add'>Add r</button>
    </template>
</dom-module>

Polymer({
    is: "my-element",
    properties: {
        r: {
            type:Object,
            value:[1,2]
        },
        length: {
            type: Number,
            computed: '_length(r)'
        }
    },
    _length: function(r) {
        return r.length
    },
    _add: function() {
        this.push('r', this.r.length+1);
        <!-- this.notifyPath('r', this.r); -->
    }

});

jsfiddle

并且无法理解,为什么repeated template刷新push新值,但computed propetycomputed binding未刷新

0 个答案:

没有答案