将 dojo.dnd.Source.checkAcceptance 更改为 true 是否会影响类型检查?

发布于 2024-10-03 00:11:28 字数 1083 浏览 0 评论 0原文

我已经有了一个有效的 DnD 实现,但是我遇到了障碍。看来,如果我将 dojo.dnd.Source.checkAcceptance 设置为 true,我这样做的源容器将停止检查 dndType,它会接受所有内容。

我正在检查 dojo.dnd.Source 容器中是否存在节点,如果存在我想禁用删除。我这样做了两次,因为如果页面加载时内容已经存在,我们希望禁止在其中删除其他内容,并且只允许源容器包含 1 个节点。 onDrop 事件也是如此。

如果 checkAcceptance = false,那么它可以工作并且不接受任何掉落,但是如果 checkAcceptance = true 那么它接受所有内容。

我正在使用 dojo 版本 1.4.2。

这是有问题的代码:

var contentSourceA = new dojo.dnd.Source("ContentCol",{accept: ["contentItem"]});  
if (dojo.query("#ContentCol")[0].children.length > 1) {  
    contentSourceA.checkAcceptance = function(){return false;}  
}else{  
    contentSourceA.checkAcceptance = function(){return true;}  
}  
dojo.connect(contentSourceA,'onDrop',function(source,node,copy){  
    if (dojo.query("#ContentCol")[0].children.length > 1) {  
        contentSourceA.checkAcceptance = function(){return false;}  
    }else{  
        contentSourceA.checkAcceptance = function(){return true;}  
    }  
});  

所以我的问题是:更改 dojo.dnd.Source.checkAcceptance 是否会影响类型检查功能?如果不是,我在这里做错了什么?我应该通过主题事件之一来执行此操作吗?

I've got a working DnD implementation however I've run into a snag. It seems that if I set dojo.dnd.Source.checkAcceptance to true, the Source container I do that to stops checking the dndType, it accepts everything.

I'm checking if there is a node present in the dojo.dnd.Source container, if there is I want to disable dropping. I do this twice because if content is already present when the page loads, we want to disable dropping additional content there and only allow the Source container to contain 1 node. Likewise for the onDrop event.

If checkAcceptance = false, then that works and doesn't accept any drops, however if checkAcceptance = true then it accepts everything.

I'm using dojo version 1.4.2.

Here's the offending code:

var contentSourceA = new dojo.dnd.Source("ContentCol",{accept: ["contentItem"]});  
if (dojo.query("#ContentCol")[0].children.length > 1) {  
    contentSourceA.checkAcceptance = function(){return false;}  
}else{  
    contentSourceA.checkAcceptance = function(){return true;}  
}  
dojo.connect(contentSourceA,'onDrop',function(source,node,copy){  
    if (dojo.query("#ContentCol")[0].children.length > 1) {  
        contentSourceA.checkAcceptance = function(){return false;}  
    }else{  
        contentSourceA.checkAcceptance = function(){return true;}  
    }  
});  

So hence my question: Does changing dojo.dnd.Source.checkAcceptance affect the type checking functionality? If not, what have I done wrong here? Should I do this via one of the Topic events?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

长亭外,古道边 2024-10-10 00:11:28

类型检查逻辑封装在 dojo.dnd.Source.checkAcceptance 函数的默认实现中。如果覆盖此函数,默认逻辑就会丢失。

您可以通过继承dojo.dnd.Source来创建自己的DnD源类:

dojo.declare("AcceptOneItemSource", dojo.dnd.Source, {
    checkAcceptance : function(source, nodes) {
       if (this.node.children.length > 1) {
           return false;
       }
       return this.inherited(arguments);
    }
});

The type checking logic is encapsulated in the default implementation of dojo.dnd.Source.checkAcceptance function. If you override this function, the default logic is lost.

You can create your own DnD source class by inheriting dojo.dnd.Source:

dojo.declare("AcceptOneItemSource", dojo.dnd.Source, {
    checkAcceptance : function(source, nodes) {
       if (this.node.children.length > 1) {
           return false;
       }
       return this.inherited(arguments);
    }
});
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文