Angular 角阵列拼接和推送不工作

Angular 角阵列拼接和推送不工作,angular,typescript,primeng,primeng-datatable,Angular,Typescript,Primeng,Primeng Datatable,我有一个奇怪的问题,我使用的是dataview,所以当我向数组中添加项时,不会将其推送到数组中。我使用chrome开发者工具确认没有任何东西被推送到阵列中 HTM(为了简单起见,只显示复选框) 非常确定这一行是您的问题,您在其中执行对象。分配给数组: this.iErsaAppList=Object.assign([],this.iErsaDeafultApps);} 我在我的控制台上试过这样: const obj = {a:'a'}; const result = Object.assign(

我有一个奇怪的问题,我使用的是dataview,所以当我向数组中添加项时,不会将其推送到数组中。我使用chrome开发者工具确认没有任何东西被推送到阵列中

HTM(为了简单起见,只显示复选框)


非常确定这一行是您的问题,您在其中执行对象。分配给数组:

this.iErsaAppList=Object.assign([],this.iErsaDeafultApps);}

我在我的控制台上试过这样:

const obj = {a:'a'};
const result = Object.assign([],obj);
// result -> [a: "a"]
// Try to access properties of array.
const item = result[0]; // undefined
我不确定这个结果数组到底发生了什么,但它看起来不像我以前见过的任何东西。我不知道从那个获取中您的响应是什么样子的,但是假设它是一个数组,当它接收数据时,您可能需要一些这样的代码

 this._ersaDet.getErsaApps()
        .subscribe(data => {
           this.iErsaApp.list = data.map(item=> item);  // map response to new array
});

当你发布很多像这样格式化的代码时,包括我自己在内,都不用费心去读。请回答您的问题并设置代码的格式,使其清晰易读,除非您不希望其他人阅读。在这种情况下,请将其完全忽略。谢谢或提示,删除了我的html并清理了我的代码删除了空格和控制台。日志此问题与数组无关。您是否看到任何行?(未添加的一行)@rgoal从您的代码中可以看出,您的表中似乎没有任何行,它从一开始就显示为空。我说得对吗?您看到行了吗?那么您的代码可能有多个问题。只是说这样你就可以改进你的问题,不要粗鲁。你应该分步工作,将问题与你的宏伟计划中不起作用的部分隔离开来,在小部分上工作。如果您的代码格式良好,我可能更倾向于看一看,但不太可能。如果您的代码是在一个交互式代码片段中,说明了这个问题,并且可以在浏览器中解决,我会更倾向于这样做。我想试试看。就目前的情况来看,我暂时不干了。在这一点上,这不是一个真正合适的s/o问题。我的答案现在可能会被否决,因为它不再适用于这个问题。事实上,我现在要否决这个问题,直到我喜欢它的样子。我重新格式化了我的代码,并试图使其简单化,同时隔离问题…它来自GetErsaApps()方法请提供任何帮助:)我找到了…它在那里,但一直到最后…我有数千行,它只是在最后添加行。
getErsaApps(): Observable<IErsaApps[]> {
        return this._http.get(environment.BASE_API_URL + 'xxxxxx')
            .map((response: Response) => <IErsaApps[]>response.json())
            .catch(this.handleError);
    }
iErsaAppList: IErsaApps[] = []; 
    selectedObject: IErsaApps; 
    selectedPreviewObject: IErsaApps; 
    iErsaDeafultApps: IErsaApps[] =[]; 
    iErsaPreviewApps: IErsaApps[]=[]; 
    iErsaSelectedApps: IErsaApps[] = null; 
 ngOnInit() {
 this.GetErsaApps();
}
 GetErsaApps() {
        this._ersaDet.getErsaApps()
            .subscribe(
            data => {
            this.iErsaDefaultApps = data;
            this.iErsaAppList = data.map(item => item);      },
       }
       togglePreviewApp(event: any) {
        if (this.iErsaAppList != undefined) {
              this.selectedPreviewObject = this.iErsaAppList
                .find(x => x.app_id == event.srcElement.value);
            const index: number = this.iErsaPreviewApps.indexOf(this.selectedPreviewObject);
            this.iErsaDeafultApps.push(this.selectedPreviewObject);
        }
    }  
const obj = {a:'a'};
const result = Object.assign([],obj);
// result -> [a: "a"]
// Try to access properties of array.
const item = result[0]; // undefined
 this._ersaDet.getErsaApps()
        .subscribe(data => {
           this.iErsaApp.list = data.map(item=> item);  // map response to new array
});