Dojo扩展dojo.dnd.Source,移动不发生。想法? [英] Dojo extending dojo.dnd.Source, move not happening. Ideas?

查看:106
本文介绍了Dojo扩展dojo.dnd.Source,移动不发生。想法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

注意:这是解决的,我将尽快发布解决方案。



嘿,所有,



好吧,我有一个简单的dojo页面与裸露的要点。三个UL与其中的一些LI。这个想法允许在它们之间进行拖放,但是如果由于最后一个项目被拖出而导致任何UL变空,我将向用户发出一个消息给他们一些说明。



为了做到这一点,我想扩展dojo.dnd.Source dijit并添加一些智能。看起来很容易为了保持简单(我正在从CDN加载Dojo)我只是声明我的扩展名,而不是在模块加载完成。声明函数在这里...

 函数declare_mockupSmartDndUl(){
dojo.require(dojo.dnd。资源);
dojo.provide(mockup.SmartDndUl);
dojo.declare(mockup.SmartDndUl,dojo.dnd.Source,{
markupFactory:function(params,node){
//params._skipStartup = true;
返回新的mockup.SmartDndUl(node,params);
},
onDndDrop:function(source,nodes,copy){
console.debug('onDndDrop!');
if(this == source){
//重新排序项目
console.debug('从我们移动项目);
// DO SOMETHING HERE
} else {
//移动项目给我们
console.debug('move items to us');
// DO SOMETHING HERE
}

console.debug( ''='+ this);
console.debug('source ='+ source);
console.debug('nodes ='+ nodes);
console.debug ='+ copy);
return dojo.dnd.Source.prototype.onDndDrop.call(this,source,nodes,copy);
}
});
}

我有一个init函数来使用它来装饰列表...

  dojo.addOnLoad(function(){
declare_mockupSmartDndUl();
if(dojo.byId list1')){
// new mockup.SmartDndUl(dojo.byId('list1'));
new dojo.dnd.Source(dojo.byId('list1'));
}

if(dojo.byId('list2')){
new mockup.SmartDndUl(dojo.byId('list2'));
// new dojo。 dnd.Source(dojo.byId('list2'));
}

if(dojo.byId('list3')){
new mockup.SmartDndUl(dojo。 byId('list3'));
// new dojo.dnd.Source(dojo.byId('list3'));
}
});

尽管如此,你会注意到我将list1作为标准的dojo dnd来源进行测试。



问题是这样 - list1会很乐意接受列表2& 3谁将移动或复制为宜人。但是列出了2& 3拒绝接受list1中的项目。就像DND操作被取消一样,但是调试器确实显示了dojo.dnd.Source.prototype.onDndDrop.call,并且参数对我来说是看起来



现在,这里的文档真的很弱,所以我从中采取了一些这个例子可能已经过时了(我使用的是1.4)。



有人可以填写我的扩展名为dijit的问题吗?



谢谢!

解决方案

最后,我打到了Dojo IRC(很棒的人),我们结束了(到目前为止)这个...

  function declare_mockupSmartDndUl(){
dojo.require(dojo.dnd.Source);
dojo.provide(mockup.SmartDndUl);
dojo.declare(mockup.SmartDndUl,dojo.dnd.Source,{
markupFactory:function(params,node){
//params._skipStartup = true;
返回新的mockup.SmartDndUl(node,params);
},
onDropExternal:function(source,nodes,copy){
console.debug('onDropExternal called ...');

// dojo.destroy(this.getAllNodes()。query(.dndInstructions));
this.inherited(arguments);

var x = source.getAllNodes()。length;
if(x == 0){
newnode = document.createElement('li');
newnode.innerHTML =你可以拖动东西在这里! ;
dojo.addClass(newnode,dndInstructions);
source.node.appendChild(newnode);
}

return true;
// return dojo.dnd.Source.prototype.onDropExternal.call(this,source,nodes,copy);
}
});
}

你可以看到我在哪里,我在源是空的(客户端规范,ug!),我需要找到一种方式来杀死它,当有东西被拖入(因为它不是,根据定义,空的任何更多的在一个收入拖动!那个部分不是工作得很好。



无论如何,魔术不是使用onDnd_____函数,而是较高级别的一个,然后调用this.inherited(arguments)来触发关闭内置功能。<​​/ p>

谢谢!


NOTICE: THIS IS SOLVED, I WILL PUBLISH THE SOLUTION HERE ASAP.

Hey all,

Ok... I have a simple dojo page with the bare essentials. Three UL's with some LI's in them. The idea si to allow drag-n-drop among them but if any UL goes empty due to the last item being dragged out, I will put up a message to the user to gie them some instructions.

In order to do that, I wanted to extend the dojo.dnd.Source dijit and add some intelligence. It seemed easy enough. To keep things simple (I am loading Dojo from a CDN) I am simply declating my extension as opposed to doing full on module load. The declaration function is here...

function declare_mockupSmartDndUl(){
dojo.require("dojo.dnd.Source");
dojo.provide("mockup.SmartDndUl");
dojo.declare("mockup.SmartDndUl", dojo.dnd.Source, {
    markupFactory: function(params, node){
        //params._skipStartup = true;
        return new mockup.SmartDndUl(node, params);
    },
    onDndDrop: function(source, nodes, copy){
        console.debug('onDndDrop!');    
        if(this == source){
            // reordering items
            console.debug('moving items from us');
            // DO SOMETHING HERE
        }else{
            // moving items to us
            console.debug('moving items to us');
            // DO SOMETHING HERE
        }

        console.debug('this = ' + this );
        console.debug('source = ' + source );   
        console.debug('nodes = ' + nodes);
        console.debug('copy = ' + copy);
        return dojo.dnd.Source.prototype.onDndDrop.call(this, source, nodes, copy);
    }   
});
}

I have a init function to use this to decorate the lists...

dojo.addOnLoad(function(){
declare_mockupSmartDndUl();
if(dojo.byId('list1')){
    //new mockup.SmartDndUl(dojo.byId('list1'));
    new dojo.dnd.Source(dojo.byId('list1'));
}

if(dojo.byId('list2')){
    new mockup.SmartDndUl(dojo.byId('list2'));
    //new dojo.dnd.Source(dojo.byId('list2'));
}

if(dojo.byId('list3')){
    new mockup.SmartDndUl(dojo.byId('list3'));
    //new dojo.dnd.Source(dojo.byId('list3'));
}
});

It is fine as far as it goes, you will notice I left "list1" as a standard dojo dnd source for testing.

The problem is this - list1 will happily accept items from lists 2 & 3 who will move or copy as apprriate. However lists 2 & 3 refuce to accept items from list1. It is as if the DND operation is being cancelled, but the debugger does show the dojo.dnd.Source.prototype.onDndDrop.call happening, and the paramaters do look ok to me.

Now, the documentation here is really weak, so the example I took some of this from may be way out of date (I am using 1.4).

Can anyone fill me in on what might be the issue with my extension dijit?

Thanks!

解决方案

In the end, I hit the Dojo IRC (great folks!) and we ended up (so far) with this...

    function declare_mockupSmartDndUl(){
    dojo.require("dojo.dnd.Source");
    dojo.provide("mockup.SmartDndUl");
    dojo.declare("mockup.SmartDndUl", dojo.dnd.Source, {
        markupFactory: function(params, node){
            //params._skipStartup = true;
            return new mockup.SmartDndUl(node, params);
        },
        onDropExternal: function(source, nodes, copy){
            console.debug('onDropExternal called...');  

            // dojo.destroy(this.getAllNodes().query(".dndInstructions"));
            this.inherited(arguments);

            var x = source.getAllNodes().length;
            if( x == 0 ){
                newnode = document.createElement('li');
                newnode.innerHTML = "You can drag stuff here!";
                dojo.addClass(newnode,"dndInstructions");
                source.node.appendChild(newnode);
            }

            return true;
            // return dojo.dnd.Source.prototype.onDropExternal.call(this, source, nodes, copy);
        }   
    });
}

And you can see where I am heading, I put in a message when the source is empty (client specs, ug!) and I need to find a way to kill it when something gets dragged in (since it is not, by definition, empty any more ona incomming drag!). That part isnt workign so well.

Anyway, the magic was not to use the onDnd_____ functions, but the higher level one and then call this.inherited(arguments) to fire off the built in functionality.

Thanks!

这篇关于Dojo扩展dojo.dnd.Source,移动不发生。想法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆