2013-04-11 108 views
0

我有一個自定義小部件無法正常工作。它正在被實例化,但它不會調用postCreate函數。我沒有收到任何錯誤消息。dojo自定義小部件不會調用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,它將在該斷點處停止,但它不會停止在postCreate函數內的代碼的斷點處。該模板本身是一個簡單的HTML文件,其中包含幾個div和一個dojox.mobile.button

UPDATE:

下面是實例代碼:

require(["pgonline/widgets/AttributeInspector2"], function(AttributeInspector) { 

    var att = new AttributeInspector({}); 

att.placeAt("attributeInspector"); 
att.startup(); 

}); 
+0

請問你的widget類實例化?解析器?編程? – BuffaloBuffalo 2013-04-11 15:33:01

+0

@BuffaloBuffalo - 我添加了實例代碼的帖子。 – Brian 2013-04-11 15:38:08

+0

你能在jsfiddle中模仿這種行爲嗎?我[設置這一個](http://jsfiddle.net/H7Zh8/39/)類似於你的(不同的事件處理程序和模塊,但相同的部件設置和實例化),並按預期工作。 – Default 2013-04-11 15:55:14

回答

2

這可能是關閉基地,但基於您的fiddle,在控制檯中的錯誤是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的需要模板,有一個根node--這樣一個解決方法,只需添加一個包含分區的模板

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