Note that there are some explanatory texts on larger screens.

plurals
  1. POhow to properly bind jquery ui behaviors in meteor?
    text
    copied!<p>I am trying to create a group of draggable DOM objects using jQuery UI's <code>.draggable()</code> that are populated through Meteor subscriptions. The code I came up with looks like</p> <pre><code>Meteor.subscribe('those_absent', function() { $( "li.ui-draggable" ).draggable( { revert: "invalid" } ); }); Meteor.subscribe('those_present', function() { $( "li.ui-draggable" ).draggable( { revert: "invalid" } ); }); </code></pre> <p>These correspond with some <code>Meteor.publish()</code> calls, so that any time the collection changes, the <code>.draggable()</code> behaviour will be attached. At least, that was my intention.</p> <p>However, it only works once - once one of these <code>&lt;li&gt;</code>'s has been dragged and dropped, then they are no longer draggable at all.</p> <p>When the objects are dropped, I'm firing a custom event that is attached to the <code>Template</code> for the item like so</p> <pre><code> $( "#c_absent .inner-drop" ).droppable({ drop: function( event, ui ) { ui.draggable.trigger('inout.leave'); } }); Template.loftie_detail.events = { 'inout.leave': function (e) { Lofties.update({_id:this._id}, {$set: {present: 'N' }}); } }; </code></pre> <p>So, my thinking is that this change to the collection on drop should propagate through the pub/sub process and re-run the <code>.draggable()</code> line above. But it doesn't seem to.</p> <p>The complete code for this can be seen here <a href="https://github.com/sbeam/in-out/blob/master/client/inout.js">https://github.com/sbeam/in-out/blob/master/client/inout.js</a> and the app is live at <a href="http://inout.meteor.com/">http://inout.meteor.com/</a> (there are some other probably unrelated issues with items randomly losing values or disappearing from the UI altogether)</p> <p>So if my understanding of how pub/sub works in Meteor is off, it would be good to know. Or is there a more efficient way to achieve this UI behavior binding that works without it?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload