将 dojo.dnd.Source.checkAcceptance 更改为 true 是否会影响类型检查?
我已经有了一个有效的 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
类型检查逻辑封装在 dojo.dnd.Source.checkAcceptance 函数的默认实现中。如果覆盖此函数,默认逻辑就会丢失。
您可以通过继承
dojo.dnd.Source
来创建自己的DnD源类: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
: