Javascript dojo自定义小部件赢得';不要调用后创建
我有一个自定义小部件不能正常工作。它正在实例化,但不会调用Javascript dojo自定义小部件赢得';不要调用后创建,javascript,widget,dojo,amd,Javascript,Widget,Dojo,Amd,我有一个自定义小部件不能正常工作。它正在实例化,但不会调用postCreate函数。我没有收到任何错误消息 出于测试目的,我已经从小部件中删除了任何额外的代码,下面是生成的代码: define(["dojo/_base/declare", "dojo/_base/lang", "dijit/_WidgetBase", "dijit/_TemplatedMixin", "dijit/_WidgetsInTemplateMixin",
postCreate
函数。我没有收到任何错误消息
出于测试目的,我已经从小部件中删除了任何额外的代码,下面是生成的代码:
define(["dojo/_base/declare",
"dojo/_base/lang",
"dijit/_WidgetBase",
"dijit/_TemplatedMixin",
"dijit/_WidgetsInTemplateMixin",
"dojox/mobile/Button",
"dojo/text!pgonline/widgets/AttributeInspector/templates/AttributeInspector.html"],
function(declare,
lang,
_WidgetBase,
_TemplatedMixin,
_WidgetsInTemplateMixin,
Button,
template) {
return declare("AttributeInspector2", [_WidgetBase, _TemplatedMixin, _WidgetsInTemplateMixin], {
templateString : template,
baseClass : "AttributeInspector2",
postCreate : function() {
dojo.connect(this, "onBeforeTransitionIn", lang.hitch(this, this.onPageLoad));
},
onPageLoad : function() {
}
});
});
我可以看出它正在实例化,因为当我在Chrome中调试时,我可以在以下行上设置断点:templateString:template
,它将在该断点上停止,但不会在post create
函数中的代码断点上停止。模板本身是一个简单的HTML文件,其中包含几个div
,以及一个dojox.mobile.button
更新:
以下是实例化代码:
require(["pgonline/widgets/AttributeInspector2"], function(AttributeInspector) {
var att = new AttributeInspector({});
att.placeAt("attributeInspector");
att.startup();
});
这可能是错误的,但根据您的情况,控制台中的错误是
Uncaught error:Invalid template
您的模板如下所示:
<div>
<button data-dojo-attach-point='prevButton' data-dojo-type='dojox.mobile.Button'></button>
<button data-dojo-attach-point='nextButton'></button>
</div>
<div data-dojo-attach-point='attributes'></div>
Dijit要求模板有一个根节点——因此作为修复,只需向模板添加一个包含div的节点
<div>
<div>
<button data-dojo-attach-point='prevButton' data-dojo-type='dojox.mobile.Button'></button>
<button data-dojo-attach-point='nextButton'></button>
</div>
<div data-dojo-attach-point='attributes'></div>
</div>
小部件类是如何实例化的?解析器?编程?@buffalo-我在帖子中添加了实例化代码。你能在JSFIDLE中模拟这种行为吗?我与您的类似(不同的事件处理程序和模块,但相同的小部件设置和实例化),它按预期工作。@默认情况下,我也这样做,它也适用于我。你能不能在准备好之前把它放好?我不认为模板行上的断点表示小部件正在实例化——它只是表示模块正在实例化loaded@Default-我很少用小提琴。我试图把这个()放在一起,但它似乎对我不起作用。