0

我正在使用 Dojo 1.8.3

我想使用 dnd 开发一个可定制的表单。我在左侧有一个表单元素列表,在dojo/dnd/Source右侧有一个容器,dojo/dnd/Target当我放下它时应该会生成 dijit。

<div class="normal" style="width: 99%;  height: 99%;" data-dojo-type="dijit/layout/BorderContainer" 
     data-dojo-props="design:'sidebar', gutters: true, liveSplitters: true">
   <div data-dojo-type="dijit/layout/ContentPane"  class="normal" style="width: 30%;  height: 80%;" 
                         data-dojo-props="splitter: true, region: 'left'">

     <div data-dojo-type="dojo/dnd/Source" data-dojo-id="form_tools" id="form_tools"  data-dojo-props="copyOnly: true"   
                                 class="container" style="width:99%;">
                        <div class="dojoDndItem" dndtype="heading">Heading</div>
                        <div class="dojoDndItem" dndtype="textbox">Text Box</div>
                        ... 
                </div>
        </div>
        <div data-dojo-type="dijit/layout/ContentPane" class="normal" id="form_container" 
                         style="width: 68%; height: 80%;" data-dojo-props="splitter: true, region: 'center'">

                <div data-dojo-type="dojo/dnd/Target" data-dojo-id="form_items" id="form_items" class="container" style="height: 80%;" accept="heading,textbox">
                        <script type="dojo/on" event="DndDrop"> form.transform_item(arguments[0], arguments[1], arguments[2], arguments[3]);//source, nodes, copy, target </script>                        </div>
        </div>
</div>

在我的 js 函数transform_item中,我正在这样做:

this.transform_item = function(){ 
var dragged_items = arguments[3].selection; 

form_items.forInSelectedItems(function(item, id, map){ 
          var dnditem = dojo.byId(id); 
          switch(item.type[0]){ 
            case "textbox": 
              var textbox = new dijit.form.TextBox({ 
                  name: "textbox", 
                  value: "This is a TextBox" 
              }, "textbox_text"); 

              // HERE IS WHERE I SHOULD INSERT THE CODE FOR GENERATING A TEXTBOX 

              require(['dojo/parser'], function(parser){ 
                parser.parse('textbox_text'); 
              }); 

              break; 
 } 
 }); 
    } 

在这一点上,当我放下 Target 时出现错误:

dojo/parser::parse() error 
TypeError: root is null 

var node = root.firstChild; 

如何让 Dojo 生成,例如 dijit.form.TextBox当我拖动“文本框”dndtype 时?

4

1 回答 1

0

已解决:我刚刚插入了textbox错误的父项,textbox_text不存在。所以不需要parse()

于 2013-01-31T09:11:20.547 回答