0

Problem is that i need info from both of jsons since either of them doesn’t contain ALL info i need. Even if i declare arrays for both jsons as global variable, i cannot access them outside $.getJSON … Thus i need $.when().then() . If i do this, new problem occurs of how to incorporate $.each since i handle arrays of json requests and not single request. [Original with $.each][1]

[Fork using $.when().then()][2]

[1]: https://codepen.io/codename11/pen/PemrXN
[2]: https://codepen.io/codename11/pen/wjroLQ?editors=0110
  • Need to explain problem and what you want to be able to do in more detail – charlietfl May 05 '18 at 16:51
  • @charlietfl I got two arrays which contain urls for json calls. In original link i used $.each for arrays but cannot cherry pick data from both of them at the same time. In fork link i used specific url with $.when().then(), which data i can cherry pick. How do i combine them so i can do this on arrays i mentioned? – Veljko Stefanovic May 05 '18 at 17:06
  • Update question with a full explanation. Not sure what you mean specifically by *"cherry pick"* or what expected results are. I suspect you need to map an array of request promises but just not clear how requests should be combined – charlietfl May 05 '18 at 17:07
  • @charlietfl In first link you can see "Streams" and "Channels" jsons. "Streams" don't contain all data like "Channels" do. Problem is that i can only filter data from "Streams" json like if (data1.stream !== null) {/* some code*/} since there is not 'stream ' in "Channels" like there is in "Streams". I'm trying to get data from "Channels" where "Streams" shows null. In Fork link i achieved this but only on single json url taken from two arrays. – Veljko Stefanovic May 05 '18 at 17:28
  • OK...so in short...make request for streams and if it has no result get channels instead? And combine them in one array or??? – charlietfl May 05 '18 at 17:30
  • @charlietfl Yes for getting info from channels when info from stream is not available. And combine said info into one additional array or even better into one js object without duplicates. I need data1.stream.channel.logo, data1.stream.channel.url, data1.stream.channel.display_name, data1.stream.channel.game and data1.stream.channel.status or equivalent from "Channels" if they are not available from "Streams". I printed both of them to see structure. – Veljko Stefanovic May 05 '18 at 17:39
  • 1
    Take a look at this demo using your streamers array https://jsfiddle.net/kv09xpdq/1. Uses array of promises for the requests and returns one result array using Promise.all() – charlietfl May 05 '18 at 18:02
  • @charlietfl Thanks man. You're a lifesaver. Your fiddle is what i tried to do, but didn't quite achieved it. Just for further reference for others who have similar problem here's my pen: "https://codepen.io/codename11/pen/rvGwXG" . Currenly adding more styling which i'll add in time. Again, thanks. – Veljko Stefanovic May 05 '18 at 22:19

0 Answers0