Reputation: 1065
I'm trying to access a content pane that has been added as a template in a widget, but I can seem to get hold of it using registry.byId:
my template -- I'm trying to access the div "map":
<div>
<div id="map"
data-dojo-type="dijit/layout/ContentPane"
data-dojo-props="region:'center'"
style="padding:0;">im a map
</div>
</div>
The widget code that attempts to access "map"
define([
"dojo/_base/declare",
"dijit/_WidgetBase",
"dijit/_TemplatedMixin",
"dojo/text!Templates/LandUse.htm",
"dijit/registry",
"dijit/layout/BorderContainer", "dijit/layout/ContentPane", "dijit/TitlePane",
], function (declare, _WidgetBase, _TemplatedMixin, LandUseTpl, registry) {
return declare([_WidgetBase, _TemplatedMixin], {
templateString: LandUseTpl,
start: function () {//I've also tried postCreate but same result
var Mymap = registry.byId("map");//this is always undefined
if (Mymap) {
alert("map found");
}
}
});
});
Instantiate my widget and call the start function on my main htm page:
...
LU = new LandUse({}, "tool");
LU.start();
...
how could I get a hold of this map div so that I can add content?
Thanks
Upvotes: 0
Views: 290
Reputation: 44685
You should inherit from dijit/_WidgetsInTemplateMixin
and make use of the data-dojo-attach-point
properties, for example:
<div>
<div id="map"
data-dojo-type="dijit/layout/ContentPane"
data-dojo-props="region:'center'"
data-dojo-attach-point="map"
style="padding:0;">im a map
</div>
</div>
If you did that correctly, you should be able to access your widget with this.map
(similar to the name given to the data-dojo-attach-point
attribute).
For example: http://plnkr.co/edit/1wBfAh3dwJxYBD1a3Eb6
Upvotes: 1