1

I look ID in an array of objects JSON. Example JSON:

{
    "Przydzial": [{
            "M": "Cos",
            "Przydzialt": [{
                    "Name": "",
                    "Przydz": "tach_1",
                    "Cos": "Pod",
                    "Ha": "20",
                    "ID": "94"
                }, {
                    "Name": "B_K",
                    "Przydz": "lea",
                    "Cos": "Chea",
                    "HA": "8",
                    "ID": "78"
                }
            }]
    }]
}

Use in controller

var foo = { //my json };
var nowy = $filter('filter')(foo.Przydzialt, { ID:78});

result:

console.log(nowy); // undefined

json is correct - validated in JSLint.

4
  • The example JSON is invalid. Extra }. Commented Jan 24, 2016 at 8:06
  • Sorry is foo not $too - json is example Commented Jan 24, 2016 at 8:12
  • Do not use polish variable names in the code Commented Jan 24, 2016 at 8:15
  • Try ($foo.Przydzialt, { ID:'78'});. like in your object "ID": "78". Commented Jan 24, 2016 at 8:45

1 Answer 1

1

As "$foo.Przydzial" is an array of objects, where every object has its "Przydzialt" attribute, you should execute $filter in a loop:

var newArray;

angular.forEach($foo.Przydzial, function (el) {
    newArray = $filter('filter')(el.Przydzialt, {ID: 78});
    console.log(newArray);
});
Sign up to request clarification or add additional context in comments.

2 Comments

It is ok only the result of good object and returns an empty array Array [ Object ] Array [ ]
Is ok - if (newArray.length>0) solved the problem.Thank you

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.