Pass values from a JSON to the html via Jquery

4

I'm trying to get the data from the JSON of the twitch and manipulate them in html, in case I wanted to put together a simple list with the online channels, using the alert it shows the channels but I thought to print the list in a ul, li without having to deal with html. Can someone tell me a way to do this?

$.ajax({
 type : "GET",
 dataType : "jsonp",
 url : "https://api.twitch.tv/kraken/streams?limit=25&offset=25",
 success: function(data){
   for(i=0;i<data.streams.length;i++){
   //alert(data.streams[i]._links.self);
   }
 }
});
    
asked by anonymous 06.01.2015 / 17:49

1 answer

5

I believe that by "without touching html" you mean putting the content on the page via javascript, right?

// transforme a lista no que você precisa (lista de li):
var listaDeLi = data.streams.map(function(elemento) {
    return "<li>" + elemento._links.self + "</li>";
});

// coloque o conteúdo gerado em algum lugar
$('#content').append("<ul>" + listaDeLi.join('') + "</ul>");
    
06.01.2015 / 18:02