【问题标题】:Dragging dnd items generates "this.manager.nodes[i] is null"拖动 dnd 项目会生成“this.manager.nodes[i] is null”
【发布时间】:2009-07-20 13:58:10
【问题描述】:

我使用 Dojo 1.3.1,目前基本上在 FF3.5 下。

我有一个 dnd 源,它也是一个目标。我通过克隆模板项以编程方式在其中添加一些节点。用户的目标是使用 dnd 来订购商品。一两个操作都可以,然后我在Firebug中得到“this.manager.nodes[i] is null”错误,然后不再考虑dnd操作。

我的 HTML (jsp),部分:

<div id="templates" style="display:none">
<div class="dojoDndItem action" id="${act.name}Template">
<fieldset>
  <legend class="dojoDndHandle" >${act.name}</legend>
  <input id="${act.name}.${parm.code}." type="text" style="${parm.style}"
    dojoTypeMod="dijit.form.ValidationTextBox"
    /><br>
</fieldset></div>
</div>

我的 Javascript 用于添加/删除 dnd 项目节点,部分:

function addActionFromTemplate(/* String */actionToCreate, /* Object */data) {
    // value of actionToCreate is template id
    var node = dojo.byId(actionToCreate + "Template");
    if (node) {
        var actNode = node.cloneNode(true);

        // make template id unique
        actNode.id = dojo.dnd.getUniqueId();

        // rename inputs (add the action nb at the end of id)
        // and position dojo type (avoid double parsing)
        dojo.query("input[type=text], select", actNode).forEach( function(input) {
            input.id = input.id + actionsCount;
            dojo.attr(input, "name", input.id);
            dojo.attr(input, "dojoType", dojo.attr(input, "dojoTypeMod"));
            dojo.removeAttr(input, "dojoTypeMod");
        });

        // insert the action at script's tail
        actionList.insertNodes(true, [ actNode  ]);

        dojo.parser.parse(actNode);

        // prepare for next add
        actionsCount++;
    }
}

function deleteAction(node) {
    var cont = getContainerClass(node, "action");
    // remove the fieldset action
    cont.parentNode.removeChild(cont);
}

感谢您的帮助...

【问题讨论】:

  • 你所拥有的看起来不错。添加/删除项目后,您是否在 dojo.dnd.Source 上调用 sync()?您可以发布您的源代码的 HTML 吗?
  • 感谢您的评论,赛斯。你认为调用 sync() 会更好吗?我认为解析就足够了。 HTML 源代码很大:当我发现执行“insertNodes(false...”) 似乎可以修复 pb 时,你真的需要它吗?
  • 如果你直接调用Source方法,你不需要调用sync。如果你在Source之外操作Source下的DOM节点,那么你应该调用sync方法。

标签: dojo drag-and-drop


【解决方案1】:

好的,看来,最后,简单地使用:

actionList.insertNodes(false, [ actNode  ]);

而不是

actionList.insertNodes(true, [ actNode  ]);

修复了 pb 。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2023-02-02
    • 1970-01-01
    • 2020-07-12
    • 1970-01-01
    • 1970-01-01
    • 2019-08-25
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多