【发布时间】:2019-07-02 02:04:01
【问题描述】:
我正在尝试更新纸张下拉菜单。第一次更新后,我看到选项数组正确地显示了新项目附加到数组中。
对该数组的任何后续添加都会出现问题,新值会出现在我之前添加的所有项目中。
任何想法为什么会发生这种情况以及如何解决?
试过了:
this.options.push(myNewOption);
this.push('options', myNewOption);
预期:
第一次添加:
this.options
0: {'john', 'smith'}
1: {'one', 'one'}
这很好。
第二次添加:
this.options
0: {'john', 'smith'}
1: {'one', 'one'}
2: {'two', 'two'}
索引 1 现在显示第二个添加的名称!
第三次添加:
this.options
0: {'john', 'smith'}
1: {'one', 'one'}
2: {'two', 'two'}
3: {'three', 'three'}
实际:
例如: 第一次添加:
this.options
0: {'john', 'smith'}
1: {'one', 'one'}
这很好。
第二次添加:
this.options
0: {'john', 'smith'}
1: {'two', 'two'}
2: {'two', 'two'}
索引 1 现在显示第二个添加的名称!
第三次添加:
this.options
0: {'john', 'smith'}
1: {'three', 'three'}
2: {'three', 'three'}
3: {'three', 'three'}
【问题讨论】:
标签: arrays polymer-2.x