2013-03-05 16 views
0

我正在嘗試爲我的web應用程序中的地圖開發一個內容樣式小部件的表格。這些小工具在Chrome和FireFox中運行得非常好,但在Internet Explorer 8中無聲無息(我在開發此應用程序時已經閱讀過很多次了)。構建生命週期的BuildRendering和PostCreate方法。該小部件是使用圖結構創建的,因此它是遞歸的。有沒有人有任何想法可以導致小部件生命週期的這兩種方法之間的失敗?Dojo小工具 - BuildRendering和PostCreate之間的無聲失敗

我在某些地方看過這個模板可能是個問題,所以我將它包含在我的節點代碼中。

這裏的小部件的簡化版本,所以你也許可以得到所發生的事情的想法:

define(['dojo/_base/declare', "dijit/_WidgetBase", "dijit/_TemplatedMixin", 
     "dijit/_WidgetsInTemplateMixin", "dojo/text!./templates/_Node.html"], 

function (declare, _WidgetBase, _TemplatedMixin, _WidgetsInTemplateMixin, template) { 

    var _Node = declare ([_WidgetBase, _TemplatedMixin, _WidgetsInTemplateMixin], { 

     templateString : template, 
     _childNodes : [], 

     constructor : function (params, srcNodeRef) { 
      lang.mixin(this, params); 
      this.inherited(arguments); 
     }, 

     buildRendering: function(){ 
      this.inherited(arguments); 
      // Execution leaves this function but never launches postCreate() 
      // buildRendering is not actually there in my code, I just have it here for 
      // debugging this particular problem. 
     }, 

     postCreate : function() { 
      // Execution never reaches this point in IE8 (probably 7 and 9 as well) 
      var newParams = { 
       "Para1": "Value1", 
       "Para2": "Value2" 
      } 
      var newNode = new Node(newParams, this.containerNode); 
      this._childNodes.push(newNode); 
     } 
    }); 

    return _Node; 

}); 

而且這裏是它的使用模板:

<div> 
    <div data-dojo-attach-point="rowNode" data-dojo-attach-event="onclick:_onClick"> 
     <span data-dojo-attach-point="contentNode"> 
      <span data-dojo-attach-point="checkContainerNode"></span> 
      <img src="${_blankGif}" alt="" data-dojo-attach-point="iconNode"> 
      <span data-dojo-attach-point="labelNode"></span> 
     </span> 
    </div> 
    <div data-dojo-attach-point="containerNode" style="display: none;"></div> 
</div> 

所以我的節點遵循這一結構,但就像我說的,在Internet Explorer中buildRendering和postCreate之間默默無聞。我已經花了很多時間了。我希望有人能在這裏幫我一把。

請不要看太多的語法,我複製我的代碼的粘貼部分,但爲了清晰起見,我對其進行了大量修改。

感謝,

Ggilmann

+0

我不能說我的答案會解決您的問題,但我只列出了一些我在查看代碼時注意到的事情。 – 2013-03-06 00:57:47

+0

我已經複製了你的代碼,並在Firefox和IE8中運行它,它似乎在兩者中都完美運行。已經嘗試運行在IE7模式,怪癖模式,兼容模式等等,都工作。我猜測什麼是突破這是沒有包括在上面的修改版本。我敢打賭,模板中的某些東西正在破壞它,因爲在buildRendering期間這些東西正在被提取和包含。試圖通過不包含_onClick()類方法或_blankGif屬性來破解它,但這些在IE8中沒有特別的破壞性。 – 2013-03-06 08:45:07

回答

1

你不必調用this.inherited(arguments);在構造函數中。 Dojo會自動鏈接構造函數。

http://dojotoolkit.org/reference-guide/1.8/dojo/_base/declare.html#id8

您還需要添加this.inherited(arguments);postCreate

您的模板沒有<img>的結束標記。

+0

感謝您的幫助,我會再次嘗試所有這些明天。我說重試,因爲我有,不幸的是已經嘗試了所有的建議。關閉img我讀的地方,它不是必需的,所以我嘗試了或不。我最初嘗試不用的繼承的調用,並將它們添加爲我嘗試的最後一件事。 postCreate中的繼承,雖然可能需要,但不會被調用,因爲它永遠不會進入後創建。有點悲觀主義者,但我會明天再試一遍。 – Ggilmann 2013-03-06 01:06:34

+1

不需要關閉HTML5中的img(假設HTML5,如果XHTML,那麼它應該包括在內)。另外,我從不使用this.inherited(參數)(如果可能),因爲在使用「use strict」時它不起作用。你的班級應該沒有任何這些工作(大多數情況下,當然也有例外)。不應該需要構造函數中的lang.mixin(this,params),因爲Dojo應該這樣做。我會拋棄構造函數方法(除非你在那裏運行更多的代碼,以便讓你的問題更容易理解)。 – 2013-03-06 08:49:49