I am trying to add elements from the server to observable array in knockout.
Here is my ViewModel:
function ArticlesViewModel() {
var self = this;
this.listOfReports = ko.observableArray([]);
self.loadReports = function() {
$.get('/router.php', {type: 'getReports'}, function(data){
for (var i = 0, len = data.length; i < len; i++){
self.listOfReports.push(data[i]);
}
}, 'json');
};
self.loadReports();
};
And it works perfectly. But I know that I can merge two arrays in javascript using concat() and as far as I know concat works in knockout. So when I try to substitute my for loop with self.listOfReports().concat(data);
or self.listOfReports.concat(data);
, nothing appears on the screen.
In the first case there is no error, in the second error tells me that there is no method concat.
So how can I concat the data without my loop. And I would be really happy to hear why my method was not working