在小胡子 Polymer 2.0 中绑定一个对象

Binding an object in mustache Polymer 2.0

属性:-

    static get properties() {
        return {
            currencies: {
                type: Object,
                notify: true,
                reflectToAttribute: true,
                value: {
                    "name": "currencies"
                }
            }
        }
    }

函数:-

            _handleCryptoData(response) {
                var responseArray = response.detail.__data.response.data;
                var btc = responseArray[0];
                var eth = responseArray[2];
                var ltc = responseArray[3];
                this.currencies.btc = btc.amount;
                this.currencies.eth = eth.amount;
                this.currencies.ltc = ltc.amount;
}

如果 console.log(this.currencies.btc) -- 我得到了我想要的值...一些数字。

问题:-

<p>BTC:- <span>{{currencies.btc}}</span> </p>
<p>ETH:- <span>{{currencies.eth}}</span> </p>
<p>LTC:- <span>{{currencies.ltc}}</span> </p>

这是在视图中绑定的方式。问题是因为 currencys is an object in view currencies.btc 不起作用。另一方面,如果我只绑定 {{currencies}},我可以看到对象输出。但是 {{currencies.btc}} 不起作用。

如何使此绑定生效。我在这里做错了什么?

这些变化:

this.currencies.btc = btc.amount;
this.currencies.eth = eth.amount;
this.currencies.ltc = ltc.amount;

不是observable to Polymer

有多种方法可以解决它,但最简单的方法可能是调用:

this.set('currencies.btc', btc.amount);
this.set('currencies.eth', eth.amount);
this.set('currencies.ltc', ltc.amount);