Error: Tried to register widget with id==grid1but

2019-04-22 17:24发布

I am currently developing my personal website
and part of my site I have a biased view pr avoid duplication of code ...
and this view I have a dojox.grid.datagrid ...
I can call this view twice in the same page (ruban.phtml) the problem is that I click on 1 button that is the appeal of this view (partial view) and then I click the 2nd button that is the appeal of this view I have an error:
Error: Tried to register widget with id == grid but that id is already registered

and to address this problem, I removed the jsId walk the grid and I declared a global variable is initialized when calling the view:

grid = dijit.getEnclosingWidget(dojo.byId("gridId1");
// soit
grid = dijit.getEnclosingWidget(dojo.byId("gridId2");

I tried but I always with the same problem:

...... onDownloadEnd:function() {

          // Update the id of the grid
            var nodeGrid = dojo.byId("ancienIdGrid");
            nodeGrid.setAttribute("id", "newIdGrid");         
            varGlobalPourId = dijit.getEnclosingWidget(nodeGrid);

}....

thank you for helping me

标签: dojo
2条回答
干净又极端
2楼-- · 2019-04-22 18:05

Dijit maintains a hash of id strings to widgets in dijit.registry (see dijit/_base/manager.js) Updating the id in the DOM will not affect that table, so I could see how it would fail if you try to create a widget with the same ID twice. How about just generating a unique id for each grid, if you need an id at all?

查看更多
Ridiculous、
3楼-- · 2019-04-22 18:22
destroy all registered id forcefully with this snippet than you go on your way!!

var ids = ["cp1","cp2","cp3"];
dijit.registry.forEach(function(w){ 
   if(dojo.indexOf(ids,id)){
        w.destroyRecursive();
   }
});
查看更多
登录 后发表回答