How can I move objects in model?


#1

Hello everyone,

I need to implement an up and down actions on selected item in array for reordering my model. I think I just need to change the index of the item in the array model but I don’t know how to perform this with ember ?

My model:

[{title: 'post 1'}, {title: 'post 2'}, {title: 'post 3'}]

I select post 2, then I click on up button and I want my array looks like

[{title: 'post 2'}, {title: 'post 1'}, {title: 'post 3'}]

I want to keep the selected item context, so the property isSelected needs to be true after the reordering.

Can you help me ? I have created a jsbin http://emberjs.jsbin.com/noduyuzezu/1/edit

Thanks you for your help and sorry for my english !


#2

Here you go

I’m just using the Ember.computed.sort computed property. I also changed some of the other logic around to selecting action and isSelected to something that made a little more sense to me.


#3

Thanks a lot, It works great ! But now, I need to add a new feature:

  • select multiple objects when I press shiftKey

I’ve added a selectedPosts property for that but I need to get the event but he’s not passed with actions, how can I do that ?

Can you help me for architecting this feature ?