S
S
SHAKIRA2015-12-29 19:53:58
JavaScript
SHAKIRA, 2015-12-29 19:53:58

How to categorize json using jQuery?

All with the coming! I have a category id in json, for example "id":"5". and I need to scatter over blocks with id="1", id="2", id="3", id="4", id="5" and so on. Please help me how to do this

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexey Chernyshev, 2015-12-29
@nanomen

Hey!
Minor block edits. The element cannot be with a numeric-only ID , you must add a letter.
For example:
According to the script, everything is simple: We go over the received data, and look for the element corresponding to it by id

var data = { "channels": [...] };

$.each(data, function(idx, el){

  var id = el.id,
      $curEl = $('#b' + id);
  
  //в зависимости от того, как именно надо раскидать данные, выводим в элемент
  $curEl.append(ДАННЫЕ);
  
  //или
  $curEl.html(ДАННЫЕ);

});

The question remains what to do with the data in this element (create sub-elements and add to the container, or something else)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question