Error: Tried to register widget with id==grid1but that id is already registered

浪子不回头ぞ 提交于 2019-12-06 21:35:59

问题


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


回答1:


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?




回答2:


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();
   }
});


来源:https://stackoverflow.com/questions/2222517/error-tried-to-register-widget-with-id-grid1but-that-id-is-already-registered

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!