Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/399.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript Typescript函数已转换为Immutable.js Typescript列表_Javascript_Typescript_Immutable.js - Fatal编程技术网

Javascript Typescript函数已转换为Immutable.js Typescript列表

Javascript Typescript函数已转换为Immutable.js Typescript列表,javascript,typescript,immutable.js,Javascript,Typescript,Immutable.js,我正在尝试使用Immutable.js列表方法将我的函数转换为新函数 我在班上有 public checkVisible:any = []; public rowChecked(index){ if (this.checkVisible.indexOf(index) === -1) { this.checkVisible.push(index); } else { this.checkVisible

我正在尝试使用Immutable.js列表方法将我的函数转换为新函数

我在班上有

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);
        }
    }
正在尝试转换为:

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');
    }
}
但immutable list函数可以执行以下操作:

this.rowChecked(0);
this.rowChecked(2);
this.rowChecked(2);
this.rowChecked now is Array[2] = [0:0, 1:2]

这不符合我的要求,似乎我没有正确使用不可变列表方法。

在第二种情况下,您尝试按索引删除。在第一种情况下,使用值。这是不一样的。你需要换线

索引
重命名为
将减少混淆

this.rowChecked(0);
this.rowChecked(2);
this.rowChecked(2);
this.rowChecked now is Array[2] = [0:0, 1:2]
this.checkVisible = this.checkVisible.delete(index);
this.checkVisible = this.checkVisible.delete(this.checkVisible.indexOf(index))