Reputation: 1477
I have a load of data for users' availability by hour for several days in the form:
availData = { "date1":arrayOfUsers, "date2":arrayOfUsers, ... }
arrayOfUsers= [ userArray, userArray, ... ]
userArray= [ "username", "h0", "h1", "h2", ... "h23" ]
I have arrayOfUsers
in that form so I can sort them according to their "h0".."h23" values.
This all works fine for one view, but I now want to use the same data and create a table containing the following for one selected "username":
date1 h0 h1 h2 ... h23
date2 h0 h1 h2 ... h23
...
So far I can do this which works:
<!-- rows of avail data... -->
<tr ng-repeat="(aDay,aUsers) in allAvailData track by $index">
<td >{{aDay}}</td>
<td ng-repeat="aUser in aUsers" ng-show="aUser[0]=='YR005'" >
<span ng-repeat="hour in aUser track by $index" ng-show="!$first">{{hour}}
</span>
</td>
</tr>
giving a 2-column table row: "date" "h0h1h2h3h4"
But what I really want is separate entries... which does not work:
<!-- rows of avail data... -->
<tr ng-repeat="(aDay,aUsers) in allAvailData track by $index">
<td >{{aDay}}</td>
<span ng-repeat="aUser in aUsers" ng-show="aUser[0]=='YR005'" >
<td ng-repeat="hour in aUser track by $index" ng-show="!$first">{{hour}}</td>
</span>
</tr>
I've not been using angular for very long and I would like to know if this sort of thing is possible rather than just restructuring the data into another array.
Questions are:
Upvotes: 0
Views: 5776
Reputation: 42669
It should work if you do something like
<tr ng-repeat="(aDay,aUsers) in allAvailData track by $index">
<td >{{aDay}}</td>
<td ng-repeat="hour in getSelectedUser() track by $index" ng-show="!$first">{{hour}}</td>
</tr>
Implement getSelectedUser
method that returns a single item from a arrayofusers
based on your filter logic.
Upvotes: 2