Polymer.prototype.splice don't behave as expected

前端 未结 1 1077
清酒与你
清酒与你 2021-01-14 22:23

I\'m doing array mutation with Polymer\'s array mutation methods.

  this.allRules = [{name: \"abc\", enabled: true}];     

  var item = this.allRules[index         


        
相关标签:
1条回答
  • 2021-01-14 23:22

    Actually the item should be removed from the array. The second time it logs out as [splices: Object] just to show more info about this array, as it has a property called splices. If you run the same thing in Firefox you will still see [object] so I guess this is just a Chrome console helper thing.

    To get the value to be updated, one way is to wrap the this.push call inside a this.async method.

      this.async(function() {
        this.push('allRules', item);
        console.log(item);
        console.log(this.allRules[0].name);
        // returns 1, meaning it's filled with one item again
        console.log(this.allRules.length);
      });
    

    Have a look at this plunker for a working sample.

    0 讨论(0)
提交回复
热议问题