0
我試圖用抽搐API和我需要了解哪些用戶在線Angularjs爲什麼/循環重寫數組項
//Initialize the App
var channels = ["ESL_SC2", "OgamingSC2", "cretetion", "freecodecamp", "storbeck", "habathcx", "RobotCaleb", "noobs2ninjas"];
var app = angular.module('Twitch', []);
//main controller
app.controller("MainController", function ($scope, $http) {
//Where controller variables are assigned
// create the game Object
var result = {};
$scope.results = [];
var stream = {};
var care = "";
$scope.streams = [];
var url = 'https://api.twitch.tv/kraken/channels/';
for (var x = 0; x < channels.length; x++) {
$http.jsonp(url + channels[x] + '?callback=JSON_CALLBACK').success(function (data) {
result = data;
var id = data._id;
var name = data.name;
$scope.url = "http://static-cdn.jtvnw.net/jtv_user_pictures/" + name + "-profile_image-" + id + "-300x300.jpeg";
$scope.image = data.logo;
$scope.name = data.name;
$scope.status = data.status;
$http.jsonp("https://api.twitch.tv/kraken/streams/" + channels[x] + "?callback=JSON_CALLBACK").success(function (data) {
var streaming = (data.stream === null) ? false : true;
if (streaming) {
result.off = 'online';
var streamTitle = data.stream.channel.status;
if (streamTitle.length > 36) {
streamTitle = streamTitle.substring(0, 33);
streamTitle += '...';
}
result.streamTitle = streamTitle;
} else {
result.off = 'offline';
data.streamTitle = '';
}
result.username = channels[x];
});
$scope.results.push(result);
console.log(result);
}).error(function (data) {
// something went wrong :(
console.log('Got nothing');
});
}
});
我創建的變量是result.off
保持狀態值的用戶
(在線/離線) 和我展示內部表這個值
<div class="container text-center text-middle" ng-controller='MainController'>
<table class="table" ng-repeat="result in results">
<tbody>
<tr ng-class="satus">
<td><a class="media-left" href="#">
<img ng-src={{result.logo}} alt="image" class="img-circle img-middle " width='50px'> </a></td>
<td>
<h4 class="media-heading">{{result.name}} <span class="label"><p>{{result.off}}</p></span></h4>
</td>
<td><h4>{{result.status}}</h4></td>
</tr>
</tbody>
</table>
</div>
result.off僅表達示出了在t時的最後一個用戶狀態他列出
編輯:我創建的變量這是reult.off(未user.off),以保持對用戶 (ONLIN /離線)狀態值和即時表示喲內表 –
這個值ur結果數組檢查result.off每個用戶的值是否包含數據 –
只有最後一個具有off屬性的對象 –