0

使用 Dojo 库运行此代码时,我收到一个小部件已注册错误。

在此处输入图像描述

在控制台中,我可以看到有一个具有此 ID 的小部件,但我无法销毁它。

function layoutDialog2(data, taskBoard, idName)
{ 
    var _idName = idName;
    var _taskBoard = taskBoard;
    var d = addDialog(); //dialog
    var idD = d.get("id"); //random ID
    var f = addNew(d, Form, {id: "f"+idD, style: "border: 1px solid red"});
    var c = addNew(d, ContentPane, {id: "cp"+idD});    

    for (var i=0; i<7; i++)
    {
        var l1 = addNew2(f, "label", {style: "1px solid green"});
        var span1 = addNew2(l1, "span", {innerHTML: "a"+i+": "});
        var t1 = addNew(l1, TextBox, {name: "a"+i, value: data["a"+i]});
        var br1 = addNew2(l1, "br", {});        
    }

    var b1 = addNew(c, Button, {label: "Change", onClick: function() { change(); }});
    var b2 = addNew(c, Button, {label: "DELETE", onClick: function() { deleteTask(); }});

    function change()
    {
        console.log(_taskBoard);
        _taskBoard.destroyRecursive(); 
        console.log(_taskBoard);

        var v1 = registry.byId("f"+idD); //get form value
        var v1 = v1.get("value");
        layoutTask(v1);
        _taskBoard.destroyRecursive();
    }

    function deleteTask()
    {
        _taskBoard.destroyRecursive();
    }

    d.show();
}
4

1 回答 1

1

您需要清除已创建的 Dijit 的任何 ID 的注册表。在我的项目中,我们创建了一个辅助函数来为我们执行此操作:

destroyFieldsByIdArray: function (fieldIdArray) {
                var i,
                    idToDestroy;
                for (i = 0; i < fieldIdArray.length; i += 1) {
                    idToDestroy = fieldIdArray[i];
                    if (dijit.byId(idToDestroy)) {
                        dijit.byId(idToDestroy).destroyRecursive(true);
                    }
                }
            }
于 2013-03-13T13:27:45.890 回答