Angularjs map array to another array

后端 未结 4 1726
忘了有多久
忘了有多久 2021-01-15 14:18

I have two arrays, Users and Employments like so:

Users       = [{id:1, name: \"ryan\"}, {id:2, name:\"Julie\"}]
Employment         


        
4条回答
  •  温柔的废话
    2021-01-15 14:58

    I dealt similar problem yesterday. If you want to use js, have to loop twice. I recommend to use the best way is to select in one query by join table if data come from single database.

    You select User by one query, and Employment for another query in database. Then, twice ng-repeat to re-arrange. Here is my solution.

    select users.*, employments.title from `users` inner join `employments` where users.id = employments.user_id; 
    

    Hope be be helpful.

提交回复
热议问题