javascript - Angularjs table with JSON embedded array -


i'm struggling display this json embedded hours array on front end in simple table (timetable) days of week columns , hours in rows. if hour exists (in json), display available green color in table cell. starts "wednesday 18th" "tuesday" 24th skipping "sunday". day has 9 hours [9,10,11,12,13,14,15,16,17] 9am 5pm.

        $scope.data          = {};         $scope.data.response = "available";         $scope.data.calendar = [                               {                                 "date": "2016-05-18",                                 "hoursavailable": [9, 10, 11, 12, 13, 14, 17]                               },                               {                                 "date": "2016-05-19",                                 "hoursavailable": [9, 10, 11, 12, 13, 14, 15, 16, 17]                               },                               {                                 "date": "2016-05-20",                                 "hoursavailable": [9, 10, 14, 15, 16, 17]                               },                               {                                 "date": "2016-05-21",                                 "hoursavailable": [9, 10, 11, 12, 13]                               },                               {                                 "date": "2016-05-23",                                 "hoursavailable": [13, 14, 15, 16]                               },                               {                                 "date": "2016-05-24",                                 "hoursavailable": [11, 12, 15, 16, 17]                               }                            ];  

html

<table class="table">     <thead>         <tr>             <th>time</th>             <th>wednesday 18th</th>             <th>thursday 19th</th>             <th>friday 20th</th>             <th>saturday 21st</th>             <th>monday 23rd</th>             <th>tuesday 24th</th>         </tr>     </thead>     <tbody>        ??      </tbody> </table> 

you're going need check see if given hour present in each day's "hours free" list. this:

<tbody>     <tr ng-repeat="hour in workhours">         <td>time: {{hour}}</td>         <td ng-repeat="entry in calendar">             {{entry.hours_free.includes(hour) ? 'free' : 'busy'}}         </td>     </tr> </tbody> 

where $scope.workhours array containing numbers 9 through 17. in version, you'd want add ng-class table cell check includes condition , apply green background.

demo


Comments

Popular posts from this blog

php - Vagrant up error - Uncaught Reflection Exception: Class DOMDocument does not exist -

vue.js - Create hooks for automated testing -

.htaccess - ERR_TOO_MANY_REDIRECTS htaccess -