Last active
October 2, 2015 06:02
-
-
Save kodamirmo/b912df7d140d74db9989 to your computer and use it in GitHub Desktop.
Sort prices
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Template.linePrice.onRendered(function () { | |
$('.collapsible').collapsible({ | |
accordion: false | |
}); | |
}); | |
Template.linePrice.helpers({ | |
getItem: function () { | |
if (Session.get('CATALOG')) { | |
var catalog=Session.get('CATALOG'); | |
var items = []; | |
for (var key in catalog) { | |
if (catalog[key].categoria == this.name) { | |
items.push(catalog[key]); | |
} | |
} | |
return sort(_.sortBy(items, 'nombre')); | |
} | |
}, | |
}); | |
var sort = function(array){ | |
var newArray = []; | |
var half = Math.floor(array.length/2); | |
for(var i=0, var j=half +1; i<=half; i++,j++){ | |
newArray.push(array[i]); | |
if(array[j]) | |
newArray.push(array[j]); | |
} | |
return newArray; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment