javascript - Nested ng-options in ng-repeat - How to get selected? -


I have a ng-repeat which lists the parts of the day to be listed for each line , I need to show available playlists.

The issue I have come up is how to do two up matches so that we can show the currently selected items in the drop down.

  & lt; Div ng-repeat = "track by deperparts in Deparparates $ Index" class = "content_dayparts" & gt; & Lt; Div class = "info_col_1" & gt; {{Daypart.name}} & lt; / Div & gt; & Lt; Div class = "info_col_2" & gt; & Lt; Select ng-model = "daypart.assignment" ng-option = "p.id as p.name as playlist" ng-change = "assign playlist ($ index, daypart.id)" & gt; & Lt; / Select & gt; & Lt; / Div & gt;  

When "Deparparates" changes, the following function is fire:

  $ scope.checkPlaylistAssignment = function () {// To loop all the playlists we need it, get my DepardIer ID and match it Angular.forEach ($ scope.playlists, function (v, i) {angular.forEach ($ scope.dayparts, function (Vb, ib) {if ($ scope.playlists [i] .daypartId == $ scope.dayparts [Ib] .id) {console.log ("We have a match:" + $ scope.playlists [i] .daypartId + "DeferPart ID is:" + $ scope.dayparts [ib] .id); $ scope.dayparts [ib] .assignment = $ scope.playlists [i];} else {console.log ("An assigned playlist is:" + $ scope.playlists [i] .daypartId + "is a daypart ID:" + $ scope.dayparts [IB] .id);}}};}); console.log ($ Scope.dayparts);}  

"daypart.assignment" is set to the playlist object, but still, the assigned playlist does not appear in the selection.What am I missing here?

Here's a screenshot of the dev console shown here that the assignment is set.

This is a screenshot of bankruptcy showing the assignment is set.

Any help is greatly appreciated. Thank you.

Although this is not the most efficient code, then for the code you have checkPlaylistAssignment In this question you should work only on the basis of the tasks provided by you.

I checked the JSfield I sent and I have created the following checkPlaylistAssignment which will provide the correct assignment object when each part is run, then for each day commodity .

What I am doing is first I index the playlist by my il and then I go through every deparpart and allocate the right playlist object. I had previously created an index so that you avoid looping through your playlist for an object every single day.

  $ scope.checkPlaylistAssignment = function () {var playlistIndexedById = {}; Angular.forEach ($ scope.playlists, functions (playlists) {playlistIndexedById [playlist.id] = playlists;}); Angular.forEach ($ scope.dayparts, Function (Deperpart) {var curr = daypart.assignment; daypart.assignment = playlistIndexedById [curr.id];}); Console.log ('playlistIndexedById', playlistIndexedById); }; $ Scope.checkPlaylistAssignment ();  

I also made an updated Bela that shows you that it works:


Comments

Popular posts from this blog

java - Can't add JTree to JPanel of a JInternalFrame -

javascript - data.match(var) not working it seems -

javascript - How can I pause a jQuery .each() loop, while waiting for user input? -