Friday, 15 July 2011

javascript - angular filter a scope down to 1 key type to prepare for send -



javascript - angular filter a scope down to 1 key type to prepare for send -

so have scope has big chunk of key value pairs, can work , create bunch of stuff before send it.

the problem having want alter scope little array of keys of id within of before send it

so have scope has obect :

$scope.myscope = {name: name 1, id: 1, order: 1}, {name: name 2, id: 2, order: 2}

and want turn

$scope.filteredscope = {1,2};

of id's. i'm wondering if can filter scope within of controller before send? i've ever used filters in stuff repeats. within of controller, filter out ids , place them in maybe new scope sending ids. possible?

thanks!

you utilize array.map (may need polyfill older browsers):

class="snippet-code-js lang-js prettyprint-override">angular.module('mymodule', []) .controller('mycontroller', function( $scope ) { $scope.myscope = [ {name: 'name1', id: 1, order: 1}, {name: 'name2', id: 2, order: 2} ]; $scope.ids = $scope.myscope.map( function(obj){ homecoming obj.id; }); }); class="snippet-code-html lang-html prettyprint-override"><script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script> <div ng-app='mymodule' ng-controller='mycontroller'> ids: {{ids | json}} </div>

javascript angularjs

No comments:

Post a Comment