Search code examples
javascriptmeteordragula

How to push the content of a container into an array using Meteor-Dragula?


I am using Meteor-Dragula. Lets says I drag a container that has the String hello into the #right DOM element. How do I access that string? Say, pushing it into a String array.

Maybe I'm on the right track with something like this?

x = [];

Template.dragulaTemplate.events({
  "drop #right1": function(el) {
    x.push(el);
  }
});

Solution

  • I think you can't use Meteor events for Meteor-Dragula. Instead, you'll need to use drake.on in order to register event listeners. For example:

    x = [];
    Template.dragulaTemplate.onRendered(function() {
      var drake = dragula([document.querySelector('#left1'), document.querySelector('#right1')]);
      drake.on('drop', function(el, target, source, sibling) {
        x.push($(el).text());
        console.log(x);
      });
    });