我在TypeScript中有这个变量:
data = {
"paragraphs": [
{ "paragraph": "" }
]
}
加载屏幕后,我想在数组中添加{ "paragraph": "" }
,如下所示。
data = {
"paragraphs": [
{ "paragraph": "" },
{ "paragraph": "" },
{ "paragraph": "" }
]
}
所以我做的是,我做了一个for循环来继续在数组中添加{ "paragraph": "" }
但是它还没有完成。
let dataParag = 3; // The int value will keep changing based on data from database
for (var i = this.data.paragraphs.length; i <= dataParag; i++) {
this.data.paragraphs = [
{ "paragraph": "" } // The paragraph will be keep added in here but I don't have any idea on how to add it
];
}
有没有什么好方法可以动态添加它?
答案 0 :(得分:0)
哦,我从未找到解决方案。这就是我做的事情:
let dataParag = 3;
for (var i = 1; i < dataParag; i++) {
this.data.paragraphs.push({ "paragraph": "" });
}