按下按钮时,我需要将数据推送到全局变量中。但是,即使我创建了一个局部变量来复制我想要推送的数据,它仍然会覆盖全局数组(之前的所有值都转换为最近推送的数据)。
全局变量:
tjoints = []
- 关节列表joints = {}
- 数字字典 - 由用户在网络浏览器上定义tableAdd(){
if (this.time == undefined) {
this.flashMessage.show('Duração do tempo faltando', {cssClass: 'alert-danger'});
} else if(this.time == 0) {
this.flashMessage.show('Duração precisa ser maior que Zero', {cssClass: 'alert-danger'});
} else {
var temp = this.joints; //----> copy of the global variable
var i = this.tjoints.push(temp); // pushing temp into the global array
this.tjoints[i-1][9] = this.time;
console.log('this.tjoints: ', this.tjoints);
}
}
HTML:
<a class="btn btn-info" style="display: inline-block (click)="tableAdd()">Add</a>