0

This is my JSON data:

{
    result: 1,
    vote_time_slots: {
    2016-08-07: {
        diff: 1080,
        slots: {
            08:42: false, 09:36: false, 06:54: false, 04:30: false,
            09:18: false, 09:00: false, 08:24: false, 05:42: false,
            06:00: false, 10:12: false, 08:06: false, 06:36: false,
            07:12: false, 07:48: false, 05:24: false, 06:18: false,
            09:54: false, 07:30: false, 10:30: false, 05:06: false,
            04:48: false
        }
    },
    2016-07-25: {
        diff: 1080,
        slots: {
            08:42: false,
            09:36: false,
            06:54: false,
        }
    },

I want the time slots like 08:42, 09:36 and so on to be getting into a drop down.

please tell me how to navigate to slots field and get only slot values Filtered on false (which is value)

<li ng-repeat="c in eventTimings | filter: ????:false"><a>{{(c)}}

how to show based on filter also?

If i have true value the respective time slot should not show in drop down.

Tajkia Rahman Toma
  • 472
  • 1
  • 5
  • 16
  • Please give more information about your json data. What do you mean by navigating ? – ngrj Jul 20 '16 at 09:50
  • navigating means i need to go to the slots object to get the information from it First from vote_time_slots-->2016-08-07-->slot--->get necessary info – user1851003 Jul 20 '16 at 10:11
  • You can use "." to access object properties or you can "navigate" by accessing the properties just like accessing array elements. For your case, vote_time_slots.2016-08-07.slots – ngrj Jul 20 '16 at 10:42

3 Answers3

1

Try like this:

slots = {
            "08:42": false, "09:36": false, "06:54": false, "04:30": false,
            "09:18": false, "09:00": false, "08:24": false, "05:42": false,
            "06:00": false, "10:12": false, "08:06": false, "06:36": false,
            "07:12": false, "07:48": false, "05:24": false, "06:18": false,
            "09:54": false, "07:30": false, "10:30": false, "05:06": false,
            "04:48": false
        };
var arr = [];
for(var prop in slots) { arr.push(prop); }
console.log(arr);

From here on you repeat on the arr

ng-repeat="opt in arr" ...
Peheje
  • 12,542
  • 1
  • 21
  • 30
0

You will have to iterate over the properties of slots (since it is in object format). Please do search in stackoverflow before asking a question.

See if the answer in following link helps and write a custom filter using the logic:

Iterate through object properties

Community
  • 1
  • 1
ngrj
  • 337
  • 1
  • 3
  • 12
0

You can try this simple solution:

<li ng-repeat="(key, value) in data.slots" ng-if='!value'>{{key}}</li>

Another approach - to create custom filter:

HTML:

<li ng-repeat="(key, value) in data.slots | custom : false">{{key}}</li>

Javascript:

.filter('custom', function() {
  return function(input, search) {
    var result = {};
    angular.forEach(input, function(value, key) {
      if (value == search) {
        result[key] = value;
      }
    });
    return result;
}});
Slava Utesinov
  • 13,410
  • 2
  • 19
  • 26