W
W
WhiteSama2015-07-08 13:32:10
JavaScript
WhiteSama, 2015-07-08 13:32:10

How to give information from json by multiple parameters?

You need to filter information from json by 2 levels:

"items":{
        "item1":{
            "0":{
                "type":"рафтинг",
                "link":"/raft/",
                "name":"Рафтинг",
                "id":"145897"
            }
        },
        "item2":{

            "3":{
                "type":"kids",
                "link":"/kids/",
                "name":"Для детей",
                "id":"145897"
            }
        }

That is, I need to filter data by item1 and type. One element is clear:
$.ajax({
                        url: $('[' + selector + ']').attr(selector),
                        dataType: 'json',
                        data: { query: request.term },
                        success: function(data) {
                            response($.map(data.items.item, function(item){
                                return item;
                            }));
                        }
                    });

Answer the question

In order to leave comments, you need to log in

2 answer(s)
I
Ivan, 2015-07-08
@WhiteSama

Well, in theory, you need to do .each on items . I won’t tell you the syntax, I did the current with xml .

D
Denis Ineshin, 2015-07-08
@IonDen

Take a look at Lodash or Underscore. They have a whole bunch of methods for working with collections, incl. sorting and more.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question