【问题标题】:How to push the content of a container into an array using Meteor-Dragula?如何使用 Meteor-Dragula 将容器的内容推送到数组中?
【发布时间】:2015-12-02 12:22:59
【问题描述】:
我正在使用Meteor-Dragula。假设我将具有字符串 hello 的容器拖到 #right DOM 元素中。如何访问该字符串?说,将它推入一个字符串数组。
也许我在这样的事情上走在正确的轨道上?
x = [];
Template.dragulaTemplate.events({
"drop #right1": function(el) {
x.push(el);
}
});
【问题讨论】:
标签:
javascript
meteor
dragula
【解决方案1】:
我认为Meteor-Dragula 不能使用 Meteor 事件。相反,您需要使用 drake.on 来注册事件侦听器。例如:
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);
});
});