【发布时间】:2019-02-28 17:14:42
【问题描述】:
我正在尝试向数组添加一些数据,但出现不可扩展错误。
组件代码:
this._store.select(p => p.collection.workspaceCollectionPages).subscribe((data: CollectionPageDbModel[]) =>{
if(data){
return data.map((collectionPageDbModel)=> {
this.collectionPages.push(collectionPageDbModel) //Getting error on this line while pushing
});}
我的数据变量中有四个对象,我试图将它们推送到 collectionPages 中,但推送时出现可扩展错误。
CollectionPageDbModel:
export class CollectionPageDbModel implements IDbModel {
public id?: number;
public collection_version_id: number;
public user_id?: string;
public name: string;
public position?: number = 0;
public contents: string;
public created_at?: string;
public updated_at?: string;
public server_id?: any;
}
谁能帮我解决这个问题
【问题讨论】:
-
请将collectionPageDbModel 类添加到您的问题中
-
collectionPages之后会发生什么?在this._store.select(之后 -
在将新对象推送到 collectionPages 时会抛出对象不可扩展错误
-
您是否在任何地方使用
preventExtensions或将this.collectionPages对象传递给可能执行此操作的函数?即使在store.select之后,由于 javascript 事件队列,这也会导致问题 -
为什么会有
return声明?我认为那里不需要这样做,因为您只是将对象推入内部。尝试删除return,您可以将其用作其他选项,例如this.collectionPages = [...this.collectionPages, collectionPageDbModel]
标签: angular typescript rxjs