Frage

I am studying dnd in dojo. json data that i get through ajax. And to show dynamic string of data has created a div form. dnd apply and look like good. but dnd does not work. when i think that because of string type. i ask for advice!

 myboard.html

 <script>
require([ "dojo/parser","dojo/dom", "dojo/on", "dojo/request", "dojo/json","dojo/_base/array"
          ,"dijit/Dialog","dijit/form/Button","dijit/form/CheckBox","dojo/query","dojo/dnd/Source","dojo/dnd/Target","dijit/layout/BorderContainer",
        "dijit/layout/TabContainer", "dijit/layout/ContentPane","dijit/layout/LinkPane",
        "dojo/domReady!" ], function(parser,dom,on,request,json,arrayUtil,Dialog,Button,CheckBox,query) {
    parser.parse();
       .....

function addTab(formCount,num){
var cont ='';
        var xhrArgs = {
                url: '/checkData',
                handleAs: "json",
                content:{
                    seq:num
                },
                load: function(data){
                    alert('ajax success:'+data);
 cont+='<div data-dojo-type="dojo/dnd/Source" class="source">'
 arrayUtil.forEach(data,function(item,i){
 cont+='<div class="dnd" data-dnd-type="a">'+data.seq+'</div>';
 cont+='<div class="dnd" data-dnd-type="b">'+data.name+'</div>';
 cont+='<div class="dnd" data-dnd-type="c">'+data.form+'</div>';
 cont+='<div class="dnd" data-dnd-type="d">'+data.desc+'</div>';
 cont+='<div class="dnd" data-dnd-type="e">'+data.writer+'</div>';
 }
 cont+='</div>';
    .....
}
War es hilfreich?

Lösung

There are several issues with your code.

First of all, you're using data.seq, data.name, data.form, ... in the forEach() loop. However, I suppose you want to use item.seq, item.name, item.form, ... in stead of that.

Then the second issue, you're missing a bracket at the end of your code, closing the forEach() loop. I suppose this part of the code is at the ....., but I cannot be sure of that.

The third issue is that the draggable items inside a dojo/dnd/Source should have the classname dojoDndItem. None of your <div>'s have that class, so none of them are draggable.

Another issue is that you're not adding the HTML inside cont to a DOM node, so it's never getting displayed. I suppose that part of the code is at the ....., but just like the other issue I can't be sure of it.

Then the last issue is that you have to parse your content by the Dojo parser to make it work. You can do that by using:

parser.parse(domNode);

Where domNode is the node that is being used to add the HTML string to it.

I edited your code and this is the result: http://jsfiddle.net/n7MxD/

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top