1

I've got a drag and drop UI basically working with jquery ui and backbone.js. My view looks like:

render: function()
{
    $(this.el).html(ich.template_bucket(this.model.toJSON()));

    $(this.el).draggable(
        {
            helper: "clone"
        }
    );

    var that = this;
    $(this.el).droppable(
        {
            hoverClass: 'ui-state-hover',
            drop: function( event, ui )
            {
                var from_bucket_id = ui.draggable.attr('id');
                var to_bucket_id = $(that.el).attr('id');
            }
        }
    );

    return this;
},

I can access the dropped on view via that, but is it possible to get a hold of the dragged view inside the droppable callback?

Alternatively, what I'm ultimately trying to do is update the two views (the dragged and dropped into views) when something happens inside a modal window that pops up (another backbone view) after the drag happens. This view doesn't share models with the two views, so I'm not sure if there's any events I can listen to.

2
  • Does this help? stackoverflow.com/questions/5013848/… Commented Nov 3, 2011 at 3:07
  • What I'm really trying to do is update a view based on data it doesn't have direct access to, so from what I can tell, there's no event I can bind to. When a related model is saved, I want these views to update. I thought it would be easiest by actually grabbing the views inside the droppable callback function. Commented Nov 3, 2011 at 3:11

1 Answer 1

2

In the dropped-on view I usually get the dragged view's model and update it. I do that by adding a cid attribute to each dragged view's el Dom element, so its easy to get in the drop function. My models are stored in a collection the dropped-on view has access to.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.