Shivam Sinha
Shivam Sinha

Reputation: 5150

Ember Sort Models

Hi I have an array of models(images) which is the model property of an ArrayController.

I want to be able to sort the the array such that when click on the image it automatically moves itself to a predefined index. (E.g. when I click an item on the array it should move to middle of the array) and the UI is updated to reflect the new position.

Here is an example of what I am trying to achieve: http://emberjs.jsbin.com/vesakafaca/1/edit?html,js,output

Also since ArrayController is/will be depreciated from v1.13 is there alternative way of doing this without using ArrayController ?

Upvotes: 0

Views: 70

Answers (1)

Tom Netzband
Tom Netzband

Reputation: 1110

Here's an updated emberjsbin of what I think you're looking for -

http://emberjs.jsbin.com/qujihihivi/edit?html,js,output


  • ArrayController vs. ObjectController doesn't matter anymore, you can just use Ember.Controller.extend as you'll see in the updated bin.

  • I did the sorting in the model by creating an Ember Array for the model and tagging the .sortBy("index") onto it.

  • I also updated the templates with new syntax, you don't need {{bind-attr}} anymore and you should use {{#each itemCollection as |item|}} instead of just {{#each itemCollection}}, makes for easier to read templates and provides consistent scope.

Hope the updated bin is helpful!

Upvotes: 1

Related Questions