当收到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的代码中?
答案 0 :(得分:0)
假设这一切都在同一个控制器中
$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>