把AngularJS数组改成ng-repeat



当收到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>

相关内容

  • 没有找到相关文章

最新更新