Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/arrays/13.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
Arrays 将未选中的用户从复选框列表(初始选中)存储到阵列-_Arrays_Angular_Typescript - Fatal编程技术网

Arrays 将未选中的用户从复选框列表(初始选中)存储到阵列-

Arrays 将未选中的用户从复选框列表(初始选中)存储到阵列-,arrays,angular,typescript,Arrays,Angular,Typescript,我有一个数组(checkeduserslist),它包含两对userid和username值。如下图所示 我的要求是,当我取消选中复选框时,这些值将存储在另一个数组中,比如“unselectedUsersList” 下面是我试图实现的一个虚拟功能 unselectExistingUser(usr: any, event: any) { if (event.target.checked == false) { this.unselectedUsersList.pus

我有一个数组(checkeduserslist),它包含两对userid和username值。如下图所示

我的要求是,当我取消选中复选框时,这些值将存储在另一个数组中,比如“unselectedUsersList”

下面是我试图实现的一个虚拟功能

    unselectExistingUser(usr: any, event: any) {
    if (event.target.checked == false) {
        this.unselectedUsersList.push(usr);
    }
    else if (event.target.checked) {
        var indx = this.unselectedUsersList.findIndex(usr);
        this.unselectedUsersList.splice(indx, 1);
    }
    console.log('unselected users :', this.unselectedUsersList);
}
参数
usr
包含要插入或删除的用户ID/密码值。在这种情况下会进行插入,但不知道在选中时如何增加的值。
提前谢谢。

我会选择另一条路。我不使用两个数组,而是使用一个数组和一个标志
isSelected

interface User {
    id: number;
}

interface SelectableUser extends User {
    isSelected: boolean;
}


class Something {
    users: SelectableUser[];
    unselectExistingUser(usr: SelectableUser, event: any) {
        this.users.map((currentUser) => {
            if (usr.id === currentUser.id) {
                currentUser.isSelected = event.target.checked; 
            }
            return currentUser;
        });;
    }
}

我会走另一条路。我不使用两个数组,而是使用一个数组和一个标志
isSelected

interface User {
    id: number;
}

interface SelectableUser extends User {
    isSelected: boolean;
}


class Something {
    users: SelectableUser[];
    unselectExistingUser(usr: SelectableUser, event: any) {
        this.users.map((currentUser) => {
            if (usr.id === currentUser.id) {
                currentUser.isSelected = event.target.checked; 
            }
            return currentUser;
        });;
    }
}