运行以下代码时通过调试获得的以下值:staredAppsArray.getItem(0)
{
"starArr": []
}
我想为starArr增加价值。
下面,我尝试了代码。但是在运行时显示未定义的错误:
let star: Starred = new Starred();
this.staredAppsArray[0].starArr.push(3);
模型类:
export class Starred {
starArr :ObservableArray<number> = new ObservableArray<number>();
}
尝试上面的代码时遇到未定义的数组错误。我想将值3添加到该json结构化数组中。
答案 0 :(得分:0)
// If you haven't already initialized staredAppsArray, you need to do that.
this.staredAppsArray = new Array<Starred>();
// Here, you create star, but it is never added to staredAppsArray.
let star: Starred = new Starred();
// Add it here.
this.staredAppsArray.push(star);
this.staredAppsArray[0].starArr.push(3);