只需修改"this.array[0]..."打字稿代码



问题是,

this.myList[0],
this.myList[1],
this.myList[2],
this.myList[3], // mylist data is 0 ~ 18...
this.myList[18]

我试着是,

for (let i = 0; i < this.myList.length; i++) {
this.myList.push(this.myList[i]);
}

但不起作用。我是这样写的,

this.myList.push(
this.myList
);

打印如下。

...
17: {name: undefined, value: Array(1), deptId: '100', deptName: 'asd', isChecked: false}
18: {name: undefined, value: Array(1), deptId: '101', deptName: 'test', isChecked: false}
// I saved it repeatedly, but it was wrong.
19: (20) [{…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, Array(20)]
// I saved it repeatedly, but it was wrong.

当事件开始时,我想再次加载存储在myList中的数据。然而,除了手动输入,我不知道该怎么做。有什么方法?我需要你的帮助。

添加+

我想实现一个无限滚动。必须再次输出其他加载数据。就像一个时钟ui。当滚动浏览相同的数据时,我想一遍又一遍地显示它。顺便说一下,这个。如果使用myList.push(this.myList(,它将不会被处理。。。索引是一种简单的处理方法吗?我不知道。我能得到帮助吗?

for ex) 
[ 1, 2, 3, ...1000 ] : myList 1st loading, 
[ 1000, 1, 2, 3, ...1000 ] : event > myList 1st + 2nd loading 
[ 1000, 1, 2, 3, ...1000 ] : event > myList 2nd + 3rd loading ...

我不知道我是否做对了,但你的问题是,这个代码

for (let i = 0; i < this.myList.length; i++) {
this.myList.push(this.myList[i]);
}

修改数组及其长度,

因此,每次添加一个项时,数组都会变长一个,依此类推。这最终会杀死你的堆,因为数组不断扩展到无穷大。

也许你想循环直到达到初始数组的长度?如果是这样,你应该循环直到

i<myList.length 

然而,的简单级联

this.myList.concat(this.myList)

this.myList = [...this.myList, ...this.myList]

将是最简单和最好的解决方案。

最新更新