我正在尝试访问已作为模板添加到小部件中的内容 Pane ,但我似乎可以使用registry.byId 来获取它:
我的模板——我正在尝试访问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>
尝试访问“ 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");
}
}
});
});
实例化我的小部件并调用我的 htm 主页面上的启动函数:
...
LU = new LandUse({}, "tool");
LU.start();
...
如何获取此 map div 以便添加内容?
谢谢
最佳答案
您应该继承dijit/_WidgetsInTemplateMixin
并使用data-dojo-attach-point
属性,例如:
<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>
如果您的操作正确,您应该能够使用 this.map
访问您的小部件(类似于 data-dojo-attach-point
的名称)属性)。
关于javascript - 作为 dojo 模板添加的小部件元素的registry.byId,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25858317/