简体   繁体   English

聚合物1.0在聚合物函数中添加变量

[英]Polymer 1.0 Adding variables in a polymer function

I am not sure if this is a bug or i am doing something wrong. 我不确定这是否是错误或我做错了什么。

I have 6 properties 我有6个住宿

(function () {
  Polymer({
    is: 'claim-type',
      properties: {
        foo: {
          type: Number,
          value: false,
          observer: 'add'
        },
        bar: {
          type: Number,
          value: false,
          observer: 'add'
        },
        ....

and so on.... 等等....

Each one is linked to a 每个链接到一个

When one changes it triggers the observer 'add' 更改时会触发观察者“添加”

add: function () {
  this.ray = this.bar + this.foo + this.etc;
}

say foo = 1 and bar = 2 and etc = 3 说foo = 1和bar = 2等等= 3

the result will equal 123 instead of 6? 结果等于123而不是6?

What am i doing wrong? 我究竟做错了什么?

EDIT : changed code from type Boolean to Number 编辑 :将代码从布尔类型更改为数字

Polymer seems to be treating the Numbers as strings. Polymer似乎将数字视为字符串。 This is probably do to the fact it is using paper-input 这可能是因为它使用纸张输入

need to add the + sign in front of the variable to convert it into a number. 需要在变量前面添加+号,以将其转换为数字。

add: function () {
  this.ray = +this.bar + +this.foo + +this.etc;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM