问题
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