Skip to content

Instantly share code, notes, and snippets.

@kodamirmo
Last active October 2, 2015 06:02
Show Gist options
  • Save kodamirmo/b912df7d140d74db9989 to your computer and use it in GitHub Desktop.
Save kodamirmo/b912df7d140d74db9989 to your computer and use it in GitHub Desktop.
Sort prices
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