简体   繁体   English

Dijot表单字段在dojo.destroy之后没有在dojo.place上解析

[英]Dijit form fields not parsing on dojo.place after a dojo.destroy

I have a table in my form called table0 that has several dijit form controls in it. 我有一个名为table0的表格,其中有多个dijit表格控件。 I also have an add and remove button to add a new table and remove the last table. 我还有一个添加和删除按钮,以添加新表并删除最后一个表。 Each new table will have an id incremented by 1. So the first click of add gives table1, 2nd click table2, etc. Each click of remove will remove the last table. 每个新表的ID都将增加1。因此,第一次单击添加将得到table1,第二次单击table2,依此类推。每次单击删除都会删除最后一个表。

Here is the add function: 这是添加功能:

        function getNewTable() {
        dojo.query('#addTable').onclick(function() {
            var tableNode = dojo.byId('table'+count);
            count++;
            dojo.xhrGet({url: 'addTable.html', 
                         handleAs: "text", 
                         preventCache: true,
                         content:{fieldId:count} ,
                    load: function(data) {
                        var newTable = dojo.place(data, tableNode, 'after');
                        dojo.parser.parse(newTable);
                    },
                    error: function(error) {
                        var newTable = dojo.place("AJAX error: " + error, deductNode, 'after');
                        dojo.parser.parse(newTable);
                    }
            });
        });
    }

The remove function is : 删除功能是:

        function removetable() {
        dojo.query('#removeTable').onclick(function() {
            if (count != 0) {
                var tableNode = dojo.byId('table'+count);
                count--;
                dojo.xhrGet({url: 'removeTable.html', 
                             handleAs: "text", 
                             preventCache: true,
                             content: {fieldId:count},
                        load: function(data) {
                                dojo.destroy(tableNode);
                        },
                        error: function(error) {
                            var newTable = dojo.place("AJAX error: " + error, tableNode, 'after');
                            dojo.parser.parse(newTable);
                        }
                });
            }
        });
    }

The count variable is declared globally. count变量是全局声明的。

The functions work correctly. 功能正常工作。

The problem I am having is when you remove a tableNode and then add a table node the node at that specific index will not execute dojo.parser.parse(newTable). 我遇到的问题是,当您删除tableNode然后添加表节点时,该特定索引处的节点将不会执行dojo.parser.parse(newTable)。

I put some output statements in my code to debug and all the references are correct. 我在代码中放入了一些输出语句进行调试,所有引用均正确。

So it works fine as long as you do not place a node with an id that has been destroyed. 因此,只要您不放置其ID已被破坏的节点,它就可以正常工作。

Example: click add, table1 id is created, dojo parses it fine, all is well. 示例:单击添加,创建了table1 id,dojo对其进行了很好的解析,一切都很好。 click remove, table1 is destroyed, still ok. 单击删除,table1被销毁,仍然可以。 click add again, table1 is created, dojo does not parse this node. 再次单击添加,就创建了table1,dojo不会解析该节点。

Am I doing something wrong? 难道我做错了什么?

Looks like I did not destroy the dijit widgets correctly. 看来我没有正确销毁dijit小部件。

I added this inside the load callback of the remove function: 我将此添加到remove函数的load回调中:

dojo.forEach(dijit.findWidgets(dojo.byId(deductNode)), function(w) {
    w.destroyRecursive();   
});
dojo.destroy(deductNode);   

I assumed destroying the dom node with dojo.destroy would also remove the dijit widgets. 我假设使用dojo.destroy销毁dom节点也将删除dijit小部件。

This is working correctly now. 现在这可以正常工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM