Home > Net >  Simply modify "this.array[0]..." the typescript code
Simply modify "this.array[0]..." the typescript code

Time:12-03

problem is,

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

I try is,

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

But doesn't work. I write it like this,

this.myList.push(
  this.myList
);

Print it out as below.

 ...
   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.

When the event starts, I want to load the data stored in myList one more time. However, I don't know how to do it other than manual input. What kind of ways are there? I want your help.

add

I want to implement an infinite scroll. Additional loading data must be output once again. Like a clock ui. When scrolling through the same data, I want to show it over and over again. By the way, this.If myList.push (this.myList) is used, it will not be processed... Is index an easy way to handle it? I don't know. Can I get help?

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 ...

CodePudding user response:

I don't know if i get it right, but your problem is, that this code

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

modifies the array and with it it's length,

So each time you add an item the array gets one longer and so on. This will eventually kill your heap for the array keeps expanding into infinity.

Maybe you want to loop until you reach the length of the inital array? If so you you should loop until

i<myList.length 

However a simple concatenation by

this.myList.concat(this.myList)

or

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

would be the easiest and best solution.

  • Related