2
나는 내가 타이프 라이터 기능은
public checkVisible:any = [];
public rowChecked(index){
if (this.checkVisible.indexOf(index) === -1) {
this.checkVisible.push(index);
}
else {
this.checkVisible.splice(this.checkVisible.indexOf(index), 1);
console.log(this.checkVisible);
}
}
이로 변환하려고이 내 수업에서
Immutable.js 목록 방법을 사용하여 새 기능 내 기능을 변환하기 위해 노력하고있어 Immutable.js 타이프 라이터 목록으로 전환 :
public checkVisible:Immutable.List<any> = Immutable.List([]);
public rowChecked(index){
if (this.checkVisible.indexOf(index) === -1) {
this.checkVisible = this.checkVisible.push(index);
}
else {
this.checkVisible = this.checkVisible.delete(index);
console.log(this.checkVisible, 'REMOVED');
}
}
첫 번째 기능은 필요에 따라 작동합니다
this.rowChecked(0);
this.rowChecked(2);
this.rowChecked(2);
this.rowChecked now is Array[1] = [0:0]
그러나 불변의리스트 기능은이 작업을 수행 : 내가 제대로 불변의 목록 방법을 사용하지 않는 것 나를 만족하지
this.rowChecked(0);
this.rowChecked(2);
this.rowChecked(2);
this.rowChecked now is Array[2] = [0:0, 1:2]
.