聚合物编号属性分配更改值

时间:2017-04-07 11:32:25

标签: properties numbers variable-assignment polymer-1.0

我有一个奇怪的问题。

我为我的加热控制实施了一个Polymer元素,并具有实际温度的属性。

该属性的值类似于23.5(浮点值)。

当我将转移的“正确”值分配给属性时,值会更改。 为了显示问题,我添加了一个控制台输出:

temperature: 23 - states[id].val: 23.2
temperature type: number states[id].val type: number

正如您在输出中看到的那样,值在赋值期间被舍入。我不使用任何观察者或可以修改价值的东西。

为什么改变价值的想法?

这是我的Polymer元素的相关部分:

<dom-module id="hm-thermostat">
  <link rel="import" type="css" href="./styles/materialdesignicons.css">
  <template>
    <style is="thermostatStyle">
      ..
    </style>
      ..
      <div class="data">
        <div class="flex-display act-vert-align">
          <div class="mdi mdi-thermometer mdi-24px margin-right"></div>
          <div class="text-width" hidden$="{{small}}">Aktuelle Temperatur:</div>
          <div class="actualTemp">{{temperature}}°C</div>
        </div>
      </div>
  </template>

  <script>
    Polymer({
      is: 'hm-thermostat',
      properties: {
        ..
        temperature: {
          type: Number
        },
        ..
      },
      ..
      dataCallback: function (states) {
        for (var id in states) {
          if (id.indexOf(this.deviceid) >= 0) {
            switch (id) {
              ..
              case "hm-rpc.0." + this.deviceid + ".1.TEMPERATURE":
                this.temperature = states[id].val;
                console.log("temperature: " + this.temperature + " - states[id].val: " + states[id].val);
                console.log("temperature type: " + typeof this.temperature + " states[id].val type: " + typeof states[id].val);
                break;
              ..
            }
          } else {
            ..
          }
        }
      }

    });
  </script>
</dom-module>

0 个答案:

没有答案