Home > Enterprise >  Display array in angular
Display array in angular

Time:01-09

I have a list that has three columns; menu, menuItem, and order.

I want to display menu and menuItem by order like this example:

Menu 1 : order 200
Menu 2 : order 230
Menu 3 : order 250 
Menu item 1 : order 210
Menu item 2 : order 360

The result will be :

  • Menu 1 have menu item 1 ( 200< 210 <230)
  • Menu 2 : don't have menu item
  • Menu 3 have menu item 2 ( because 250 < 360).

I do that in two lists (one for the menu and one for the item menu ) and when the value for item is between the menu index 1 and last menu index 2, I save it in a new list to display. But I have a problem with the new list: I can't have the value for every menu.

Can anyone could help me?

For(I=0; I< list1.length ;I  ){
 let nextMenu = list1.order[I 1];
 for (j=0;j<list2.length ;j  ){
  let item = list2[j].order;
  let menu = list1[I].order;
 if(menu < item < Next menu){
 This.list3.push(list2[j]);
  }
}
}
```![enter image description here](https://i.stack.imgur.com/1TjDE.jpg)

CodePudding user response:

You simply have to treat the last item separately.

For instance, try in this way (you can refactor code in a better way, is just an example):

(I leave you enter image description here

I update the STACKBLITZ as well.

  •  Tags:  
  • Related