Javascript 如何在只读聚合物1.x属性中设置子属性

Javascript 如何在只读聚合物1.x属性中设置子属性,javascript,polymer,polymer-1.0,Javascript,Polymer,Polymer 1.0,如何在不完全替换其值的情况下在Polymer中设置只读子属性 Polymer({ is: 'my-element', properties: { foo: { type: Object, value: function() { return {bar:1, baz:2}; }, readOnly: true, notify: true } },

如何在不完全替换其值的情况下在Polymer中设置只读子属性

Polymer({
    is: 'my-element',

    properties: {
        foo: {
            type: Object,
            value: function() { return {bar:1, baz:2}; },
            readOnly: true,
            notify: true
        }
    },

    observers: [
        '_onBarChanged(foo.bar)',   // this should fire
        '_onBazChanged(foo.baz)'    // this not
    ],

    // how do I set this.foo.bar without completely replacing this.foo
    ready: function() {
        // the only way I found is completely replacing it's value
        let temp = Object.assign({}, this.foo, {bar: 3});
        this._setFoo(temp); 
    }
});
感觉好像我遗漏了什么。

什么时候,您应该使用
this.set('foo.baz',value)
而不是
this.foo.baz=value
,以便发出更改通知

HTMLImports.whenReady(()=>{
聚合物({
是‘x-foo’,
特性:{
傅:{
类型:对象,
只读:对,
值:()=>({bar:2,baz:4})
}
},
观察员:[
"(foo.bar)",
"(foo.baz)",
],
_barChanged:功能(bar){
console.log('bar',bar);
},
_baz:功能(baz){
控制台日志('baz',baz);
},
_changeBar:function(){
this.set('foo.bar',this.foo.bar==5?3:5);
},
_changeBaz:function(){
this.set('foo.baz',this.foo.baz===3?5:3);
}
});
});

酒吧:[[foo.bar]]
baz:[[foo.baz]]
更改栏
改变
当使用时,应使用
this.set('foo.baz',value)
而不是
this.foo.baz=value
,以便发出更改通知

HTMLImports.whenReady(()=>{
聚合物({
是‘x-foo’,
特性:{
傅:{
类型:对象,
只读:对,
值:()=>({bar:2,baz:4})
}
},
观察员:[
"(foo.bar)",
"(foo.baz)",
],
_barChanged:功能(bar){
console.log('bar',bar);
},
_baz:功能(baz){
控制台日志('baz',baz);
},
_changeBar:function(){
this.set('foo.bar',this.foo.bar==5?3:5);
},
_changeBaz:function(){
this.set('foo.baz',this.foo.baz===3?5:3);
}
});
});

酒吧:[[foo.bar]]
baz:[[foo.baz]]
更改栏
改变