小编Bun*_*kul的帖子

如何将对象列表复制到另一个[Typescript]

我只想将值从“全部”复制到“可用”,有时我也无法从可用中获取价值。

我尝试了很多方法,例如slice()Array.from()=它不起作用

let a = [{"key":66,"value":"MAAA","username":"MAZA007"},{"key":66,"value":"MAAA","username":"MAZA007"}];

let all = a
let available = all
Run Code Online (Sandbox Code Playgroud)

我的变量没有值

这是我的完整功能

          protected  async processMoverBox(projectId?:number) {


            let available;
            let all;

            if(projectId != undefined)    
            {

                let projectTeamId =  await this.restful.get("api/operation/S200100/allprojectteam/"+projectId); 
                    console.log(projectTeamId)

                     all = projectTeamId.map((id) => {return this.copy(this.allUser.find(allUser => allUser.key == id))})

            }  
            else{ all = this.copy(this.allUser); console.log(this.allUser)}
            console.log(all);

            let a = [{"key":66,"value":"MAAA","username":"MAZA007"},{"key":66,"value":"MAAA","username":"MAZA007"}]


            available = [...a];

            console.log(available);
            console.log(JSON.stringify(available, null, 4));

            if(this.selected.length>0){
            this.selected.forEach((ms)=>{
                available.splice(available.findIndex(e => e.key == ms.key), 1);
            })
             }

             console.log(available);
             console.log(this.selected) …
Run Code Online (Sandbox Code Playgroud)

typescript-typings angular

2
推荐指数
1
解决办法
6508
查看次数

标签 统计

angular ×1

typescript-typings ×1