Dojo - “Tried to register widget with id==centerPane but that id is already registered”

别说谁变了你拦得住时间么 提交于 2019-12-24 00:48:37

问题


I'm having trouble with a content pane in Dojo where it is appearing for a second with the content then disappearing. I am getting the following error:

 Uncaught ReferenceError: dijit is not defined index.php:22
    dojo/parser::parse() error 
    Error
    arguments: undefined
    get stack: function () { [native code] }
    message: "Tried to register widget with id==centerPane but that id is already registered"
    set stack: function () { [native code] }
    type: undefined
    __proto__: d

I have come accross answer where you can destroy all registered ID's but I am still getting the error when I try them.

var ids = ["contentPane"];
dijit.registry.forEach(function(w){ 
   if(dojo.indexOf(ids,id)){
        w.destroyRecursive();
   }
});

and

var ids = ["contentPane"];

dijit.registry.forEach(function(w){ 
   if(dojo.indexOf(ids,1)){ // 1 will be yourid it will get destroy
        w.destroyRecursive();
   }
});

How do I solve this error?


回答1:


Solved it, was something simple but I'll stick the answer up in case anyone else does my mistake. My original code:

    <script>
      require(["dojo/parser", "dijit/layout/BorderContainer", "dijit/layout/ContentPane"],
        function (parser) {
        parser.parse();
      });
</script>

Fixed code:

<script>
  require(["dojo/parser", "dijit/layout/BorderContainer", "dijit/layout/ContentPane"]);
</script>



回答2:


I faced this issue when parseOnLoad was set to true. In my understanding it enables the Widget registration. Once I disabled the error gone.

<script type="text/javascript">
    var dojoConfig = {          
        parseOnLoad:false,

.....



来源:https://stackoverflow.com/questions/14664007/dojo-tried-to-register-widget-with-id-centerpane-but-that-id-is-already-regi

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