简体   繁体   中英

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

(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

the result will equal 123 instead of 6?

What am i doing wrong?

EDIT : changed code from type Boolean to Number

Polymer seems to be treating the Numbers as strings. 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;
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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