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.

3
  • Please give more information about your json data. What do you mean by navigating ? Commented Jul 20, 2016 at 9: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 Commented Jul 20, 2016 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 Commented Jul 20, 2016 at 10:42

3 Answers 3

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" ...
Sign up to request clarification or add additional context in comments.

Comments

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

1 Comment

please tell me how to navigate to slots in my JSON to get information from it
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;
}});

3 Comments

please tell me how to navigate to slots in my JSON to get information from it
This answer gives you a complete picture of what to do. I don't get your question, what do you mean by "navigate to slots"?
@user1851003: For example: var data = yourJson['2016-08-07'];

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.