Reputation: 153
Am receiving data in form of {room1: 4, room2: 2}
received in a name of roomData
$scope.testdata = [{
'room': 'room0',
'users': '10'
}];
$scope.setLobbyRoom = function (roomData) {
$scope.inc = 0;
for (i in roomData) {
//want to push the data into the array list here.
}
}
Upvotes: 0
Views: 2371
Reputation: 153
$scope.testdata = [];
$scope.setLobbyRoom = function (roomData) {
$scope.testdata = [];
for (i in roomData) {
$scope.testdata.push({
room: i,
users: roomData[i]
});
}
}
This works
Upvotes: 0
Reputation: 45232
Is roomData
an array? If so, it's as simple as:
$scope.testData = $scope.testData.concat(roomData);
Upvotes: 1
Reputation: 2315
If you want to push the data to $scope.testdata, all you have to do is to use the method push
$scope.testdata = [{
'room': 'room0',
'users': '10'
}];
$scope.setLobbyRoom = function (roomData) {
$scope.inc = 0;
for (i in roomData) {
$scope.testdata.push(roomData[i]);
}
}
Upvotes: 1