Reputation: 18059
Here is the deal. I got some pieces inside containers and I want to be able to drag and drop pieces from one containers into another (from the view side), however in order to update my models I need target's (i.e. container where I dropped my piece) position.
Here is a short jsfiddle that demonstrates my problem: container piece fiddle. For example draw the bottom piece into the middle container. I expected to see
2
1
But got 2 2
instead. Further more I expected target to match my drop target (in this case a container).
Note: This used to work on jQuery 1.6.4 but stopped working once I moved onto 1.7.
Upvotes: 0
Views: 1702
Reputation: 18059
Anyway I figured this one out myself. It was rather easy - had to change ui.draggable.data("p_pos")
to this.draggable.data("c_pos")
since in jQuery 1.7.1 treats dragged parameter correctly as $(this)
in previous version I acquired that param via ui.draggable.
Here is the new fiddle: http://jsfiddle.net/rtxRa/22/ that works correctly.
Upvotes: 0
Reputation: 4415
What is it exactly that you want to do here? Are you not looking for http://jqueryui.com/demos/sortable/?
You should also move your functions outside of the $(document).ready(function(){
. There's no reason to load those after page load.
Hmm, the issue seems to be that you don't set the pos
on drop
. It simply doesnt get updated?
drop: function(ev, ui){
var pos = $(ev.target).data('p_pos');
var oldpos = ui.draggable.data('p_pos');
console.debug(pos);
console.debug(oldpos);
console.debug($(ev.target));
}
Upvotes: 1