在自定义小部件中添加dojo小部件
问题描述:
答
首先,我不擅长英语,但会尽我所能。
这是我的小部件的路径。
这里。必须声明的js文件中的重要代码。
dojo.provide("gissoft.dijit.widgetOam");
dojo.require("dojo.parser");
dojo.require("dijit._Widget");
dojo.require("dijit._Templated");
dojo.declare("gissoft.dijit.widgetOam", [dijit._Widget, dijit._Templated], {
widgetsInTemplate: true,
basePath: dojo.moduleUrl("gissoft.dijit"),
templatePath: dojo.moduleUrl("gissoft.dijit", "templates/widgetOam.html"),
constructor: function() {
},
postMixInProperties: function() {
},
postCreate: function() {
},
startup: function() {
}
});
而在文件widgetOam.html(的templatePath)
<div> <!-- do not add tag <html> , <head> , <body> but must have <div> first -->
Hello World.
</div>
这是如何从我的Default.aspx插件调用
之前必须先添加此打电话给道场图书馆
<script>
djConfig = {
parseOnLoad: true,
baseUrl: './',
modulePaths: { 'gissoft.dijit': 'js/gissoft/dijit' }
};
</script>
和身体
<body class="tundra">
<form id="form1" runat="server">
<div>
<div data-dojo-type="gissoft.dijit.widgetOam"></div>
</div>
</form>
</body>
答
如果我理解正确的话,你是问如何包含您的自定义窗口小部件中的另一个部件。如果是这样的话,那么我们不得不修改OammieR的答案,因为它对于你的问题并不完整。 要包括你的自定义窗口小部件内的其他部件,你应该将它们包含在你的widget声明:
dojo.provide("gissoft.dijit.widgetOam");
dojo.require("dijit.form.Button"); //<- this the standard widget you want to have in your widget
dojo.require("dojo.parser");
dojo.require("dijit._Widget");
dojo.require("dijit._Templated");
dojo.declare("gissoft.dijit.widgetOam", [dijit._Widget, dijit._Templated], {
widgetsInTemplate: true,
basePath: dojo.moduleUrl("gissoft.dijit"),
templatePath: dojo.moduleUrl("gissoft.dijit", "templates/widgetOam.html"),
特别重要的是“widgetsInTemplate:真”的一部分,它告诉解析器期望部件内部的部件。
然后,您只需为要包含在小部件模板中的特定小部件添加HTML标记即可。
<div> <!-- do not add tag <html> , <head> , <body> but must have <div> first -->
<button data-dojo-type="dijit.form.Button" type="button" data-dojo-attach-point="_innerWidget" data-dojo-attach-event="ondijitclick:_onClick">Yo!</button>
</div>
dojoAttachPoint是有用的,让你可以在你的widget的实现这个widget通俗易懂的参考,而不通过dijit.byId(“”),得到一个参考。
希望这会有所帮助。
如果我想在运行时将一个自定义Widget添加到另一个自定义Widget中,该怎么办?例如我做了'声明(“_ MyCustomWidgetContainer”,...)''在其'this.domNode'中有一个'ul',并且'声明了(“_ MyCustomWidgetItem”,...)'(分解为' li'),我想插入'ul'? – 2012-05-11 12:17:38
@ NeelBasu先生,如果我不想错过这一点。你问我可以添加一个自定义的Widget到另一个自定义的Widget吗?答案是肯定的,你可以。并看到domNode工作[这里](http://dojotoolkit.org/documentation/tutorials/1。6/dom_functions /) – OammieR 2012-05-11 13:07:42