当收到websocket消息时运行以下代码:
connection.onmessage = function (eventInfo) {
var onConnectionMessage = JSON.parse(eventInfo.data);
if (onConnectionMessage.messageType === "newRequest") {
getQuizRequests();
}
}
getQuizRequests()是以下函数:
function getQuizRequests() {
var URL = '/acceptOrReject/' + lookUpCode();
$http.get(URL)
.success(function (data) {
for (var i = 0; i < data.teamArray.length; i++) {
teamArray[0] = data.teamArray[i];
}
})
.error(function (data, status) {
alert("ERROR data cant be loaded");
});
}
我想在ng-repeat中调用这个teamArray。我如何将这个数组填充到我使用ng-repeat的代码中?
假设这些都在同一个控制器
$scope.teamArray = [];
function getQuizRequests() {
var URL = '/acceptOrReject/' + lookUpCode();
$http.get(URL)
.success(function (data) {
for (var i = 0; i < data.teamArray.length; i++) {
$scope.teamArray.push(data.teamArray[i]);
}
})
.error(function (data, status) {
alert("ERROR data cant be loaded");
});
}
然后在html
中<ul ng-show="teamArray.length > 0" ng-repeat="member in teamArray">
<li>{{member}}</li>
</ul>