I'm wondering if anyone could help me find a way to use data pulled from an api and stored as a property in one method into another. This is kinda what I'm looking at atm (not the full code but everything that's relevant), I want to use the data saved in the channel method in the populate method. Thank you for any help, I hope that's an obvious enough explanation. :)
Fixed :D but I don't think I can answer because the question was apparently a duplicate *
var viewer = { init: function () { var i; this.url = "https://wind-bow.glitch.me/twitch-api/"; for (i = 0; i < userArray.length; i += 1) { this.callAPI(userArray[i]); } }, callAPI: function (users) { var firstCall = $.get(this.url + "channels/" + users, "jsonp"); var secondCall = $.get(this.url + "streams/" + users, "jsonp"); $.when(firstCall, secondCall).done(this.userData).then(this.populate); }, userData: function (data, get) { if (data[0].logo === null) { this.avatar = "<img class=\"logo\" src=\"http://via.placeholder.com/50x50\" />"; } else { this.avatar = "<img class=\"logo\" src=\"" + data[0].logo + "\" />"; } if (get[0].stream === null || get[0].stream.isUndefined) { this.status = "Offline" } else { this.status = get[0].stream.channel.status; } this.displayName = data[0].display_name; }, populate: function () { var list = new List(); list.add(new User(this.avatar, this.displayName, this.status)); list.draw(getWrapper); } }; viewer.init();
}());