0

Firstly, I sync the collection with server, then I need to render. After this, user can press the button to shuffle data in page( e.g. list of songs ), and script must rerender all items. I wrote this:

  AppCollection.on("add"  , onUpdateItem );

  $( document ).bind("keyup", function(e){
   if( e.keyCode === 13 ) {
     var shuffledCopy = AppCollection.clone().shuffle();
     $("body").html("");
     AppCollection.reset().add( shuffledCopy );
  }
});

Maybe you know best pratice for this goal?

1 Answers1

0

I would make use of custom comparators, one with shuffling functionality and the other with default sorts. That way you could swap out comparators per need and just call AppCollection.sort.

stakolee
  • 893
  • 1
  • 7
  • 20