【问题标题】:How to set container specific options in Aurelia-Dragula?如何在 Aurelia-Dragula 中设置容器特定选项?
【发布时间】:2019-07-01 14:25:04
【问题描述】:

我在我的应用程序中使用 Aurelia-Dragula (https://github.com/michaelmalonenz/aurelia-dragula),我想像在非 Aurelia Dragula 中一样为每个容器设置选项。

在我的情况下,我想在我想要 option.copy = true 的地方拥有 ContainerA,在我想要 option.removeOnSpill = true 的地方拥有 ContainerB。所以我都尝试了:

.plugin('aurelia-dragula', (options) => {
            options.removeOnSpill = true;
            options.copy = true;
        })

但结果是复制占了上风,removeOnSpill 不起作用。

登录到控制台时,选项变量在 aurelia-dragula 中的外观: {"containers":[],"copy":true,"copySortSource":false,"revertOnSpill":true,"removeOnSpill":true,"direction":"vertical","ignoreInputTextSelection":true,"mirrorContainer":{}}

如何在非 Aurelia Dragula 中完成的示例(来源:https://bevacqua.github.io/dragula/):

dragula([document.getElementById(left), document.getElementById(right)], {
  copy: function (el, source) {
    return source === document.getElementById(left)
  },
  accepts: function (el, target) {
    return target !== document.getElementById(left)
  }
});

由于选项设置的不同,我在 aurelia-dragula 中找不到这方面的文档,我无法翻译它。

【问题讨论】:

  • 看来作者最近刚刚对lib做了一些改动,也许你应该在repo中问一下?我知道这违背了提交错误的精神,但那里的交通仍然很顺畅,所以我猜他不会介意在那里回答你。如果你能得到答案,如果你能在这里发一个链接就太好了。
  • 非常感谢您的回复。由于您描述的相同原因,我不想在回购中询问,但如果这里没有更多回复,我可能会在明天这样做。

标签: aurelia dragula


【解决方案1】:

Righto - 所以是的,这绝对有可能。

我没有对此进行测试,但我相信这会起作用:

view.html

<template>
  <aurelia-dragula containers.one-way="containers" copy.call="shouldCopy(item, container)" accepts.call="shouldAccept(item, target, source, reference)"></aurelia-dragula>
</template>

viewmodel.js

export class ViewModel {

  get containers () {
    return [document.getElementById(left), document.getElementById(right)]
  }

  shouldCopy (item, container) {
    return container === document.getElementById(left)
  }

  shouldAccept(item, target, source, reference) {
    return target !== document.getElementById(left)
  }
}

【讨论】:

  • 感谢 Michael 部分解决了这个问题。剩下的是 shouldCopys 参数未定义,而 shouldAccept 工作正常。查看 aurelia-binding.js,当它对 shouldAccept 的参数运行 evalList 时,它们被填充,而 shouldCopy 参数均未定义。在调试参数路由以到达 evalList 时, shouldAccept 由 Dragula-and-drop.js 中的 DragulaAndDrop.prototype._accepts 运行,而 shouldCopy 则不会,如果这会给您任何指示
  • 谢谢你 - 有一个错误。复制功能被拖动引擎调用,而不是拖放元素。因此,它没有被称为 aurelia binding 的预期方式,因此错误地传递了参数。我在 v2.0.3 中发布了修复
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-05-27
相关资源
最近更新 更多