【问题标题】:Binding an object in mustache Polymer 2.0在 mustache Polymer 2.0 中绑定对象
【发布时间】:2018-06-18 00:44:37
【问题描述】:

属性:-

    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>

这就是 this 在视图中的绑定方式。问题是因为货币是货币视图中的一个对象。btc 不起作用。另一方面,如果我只绑定 {{currencies}} 我可以看到对象输出。但是 {{currencies.btc}} 不起作用。

如何使这种具有约束力的工作。我在这里做错了什么?

【问题讨论】:

    标签: javascript data-binding binding polymer mustache


    【解决方案1】:

    这些变化:

    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);
    

    【讨论】:

    • 完美。现在工作。这个可观察到的事情并不仅仅让我想到。非常感谢:)
    猜你喜欢
    • 1970-01-01
    • 2016-06-08
    • 1970-01-01
    • 1970-01-01
    • 2014-11-06
    • 1970-01-01
    • 2017-07-22
    • 1970-01-01
    • 2017-08-07
    相关资源
    最近更新 更多