javascript - organize array when data changes -


i have array in $scope variable looks this:

$scope.objects: [   {selected: true, description: 'string1'},   {selected: false, description: 'string2'},   {selected: true, description: 'string3'},   {selected: true, description: 'string4'} ] 

the "selected" property can changed checkboxes rendered in ui.

i'm looking method watch "selected" properties in array. every time changes, array needs reordered.

the objects "selected:false" need put on end of array. array above this.

$scope.objects: [   {selected: true, description: 'string1'},   {selected: true, description: 'string3'},   {selected: true, description: 'string4'},   {selected: false, description: 'string2'} ] 

if, example selected-value of second element changed false, array should this:

$scope.objects: [   {selected: true, description: 'string1'},         {selected: true, description: 'string4'},   {selected: false, description: 'string3'},   {selected: false, description: 'string2'} ] 

can me this?

greetz

you should write filter sorting you.

i try this, using lodash.
snippet not tested or anything, written in notepad, give startingpoint.

app.filter('sortselected', function() {     return function(items) {         var groups = _.groupby(items, 'selected');     };     var selected = _.sortby(groups[true], 'description');     var unselected = _.sortby(groups[false], 'description');      return selected.concat(unselected); }); 

Comments

Popular posts from this blog

Magento/PHP - Get phones on all members in a customer group -

php - .htaccess mod_rewrite for dynamic url which has domain names -

Website Login Issue developed in magento -