javascript - Using lodash array functions on Restangular collections -


i'm using restangular angularjs, , iterate on collection in function of controller, need modify collection returned restangular:

var ordercontroller = [ '$scope', '$http', 'restangular',   function($scope, $http, restangular) {     $scope.orders = restangular.all('orders').getlist();     $scope.toggleorder = function(order) {       _.foreach($scope.orders, function(order) {         console.log(order); // not order!         order.someproperty = false; // goal       });     });   }]; 

i think problem $scope.orders promise, not actual array, _.foreach tries iterate on properties of promise instead of objects. same result angular.foreach.

how can iterate on restangular resource collections? i'd have access collection functions of lodash, such _.filter, well.

restangular.all('orders').getlist() - promise, not array.

assign list using $object:

$scope.orders = restangular.all('orders').getlist().$object; 

list empty array until request complete.

update full code question (includes orders modification on request complete)

$scope.orders = [];  function modifyorders(orders){ ... }  restangular.all('orders').getlist().then(function(orders){  modifyorders(orders);  $scope.orders=orders; });  $scope.toggleorders = function(toggledorder){  _.foreach($scope.orders, function(order) { ... }); }; 

Comments

Popular posts from this blog

c# - How Configure Devart dotConnect for SQLite Code First? -

java - Copying object fields -

c++ - Clear the memory after returning a vector in a function -