2012-05-29 61 views
0

我有下面的代碼,我嘗試手動解析,因爲我在此示例後面創建了一個預加載器(http://acuriousanimal.com/blog/)十二分之二千零一十/ 05 /如何到創建-A-預加載功能於道場/):parser.parse()無法在IE9容器中解析(dojo 1.7.2)

<div id="appLayout" class="demoLayout" data-dojo-type="dijit.layout.BorderContainer" 
     data-dojo-props="design: 'headline', style: 'width: 100%; height:100%'"> 
     <div id="contentTabs" class="centerPanel" data-dojo-type="dijit.layout.TabContainer" 
      data-dojo-props="region: 'center', tabPosition: 'top', style: 'width: 100%; height:100%'"> 
      <div data-dojo-type="dijit.layout.BorderContainer" id="inbox" title="Inbox" data-dojo-props="design: 'headline', style: 'width: 100%, height:100%'"> 
       <div data-dojo-type="dijit.layout.ContentPane" data-dojo-props="region: 'left', splitter: true" 
        style="width: 50%; height:100%;"> 
        <div id="grid"> 
        </div> 
       </div> 

       <div id="emailcontainer" class="demoLayout" data-dojo-type="dijit.layout.BorderContainer" 
        data-dojo-props="design: 'headline', region: 'center', style: 'width: 100%; height:100%'"> 
        <div id="emailUserAccounts" data-dojo-type="dijit.layout.ContentPane" data-dojo-props="region: 'top', style: 'width: 50%; height:14px'"> 
         User Reports 
        </div> 
        <div id="emailbody" data-dojo-type="dijit.layout.ContentPane" data-dojo-props="region: 'center', style: 'width: 50%;'"> 
         Select an E-Mail from the Inbox 
        </div> 
       </div> 

      </div> 
     </div> 

     <div id="toolbar" class="edgePanel" data-dojo-type="dijit.layout.ContentPane" data-dojo-props="region: 'top'" 
      style="text-align: right;"> 

       <input id="searchtext" type='text' size='50' style="height: 30px;" /> 

       <button id="searchbtn" type="button" style="width: 120px"> 
        Search</button> 
         <button id="invertbtn" type="submit" style="width: 120px"> 
          Invert Status</button> 
      <div id="supportstaffselect"> 
      </div> 

       <button id="assignbtn" type="button" style="width: 120px"> 
        Assign</button> 
      <select id="priorityselect" data-dojo-type="dijit.form.Select" name="priorityselect"> 
       <option value="0">Low</option> 
       <option value="1" selected="selected">Normal</option> 
       <option value="2">Medium</option> 
       <option value="3">High</option> 
       <option value="4">+1</option> 
      </select> 

       <button id="prioritybtn" type="button" style="width: 120px"> 
        Change Priority</button> 
         <button id="newMessage" type="button" style="width: 120px"> 
          New Message</button> 
           <button id="replybtn" type="button" style="width: 120px"> 
            Reply</button> 
             <button id="replyallbtn" type="button" style="width: 120px"> 
              Reply All</button> 
               <button id="forwardbtn" type="button" style="width: 120px"> 
                Forward</button> 
     </div> 
     <div id="filtersnavigation" data-dojo-type="dijit.layout.ContentPane" data-dojo-props="region: 'left'" style="width: 130px;"> 
      <ul class="filterlist"> 
       <li class="filterlistitem" id="everythingfilter">Everything</li> 
       <li class="filterlistitem" id="openfilterid">Open</li> 
       <li class="filterlistitem" id="closedfilterid">Closed</li> 
       <li class="filterlistitem" id="unrepliedfilterid">Unreplied</li> 
       <li class="filterlistitem" id="repliedfilterid">Replied</li> 
       <li class="filterlistitem" id="minefilterid">Mine</li> 
       <li class="filterlistitem" id="mineunrepliedfilterid">Mine 
        Unreplied</li> 
      </ul>   
     </div>    
    </div> 

此代碼分析和正確加載在Firefox和Chrome沒有問題或錯誤,但parser.js拋出arbirtrary嘗試通過在腳本中調用解析BorderContainer或TabContainer解析IE9中的錯誤parser.parse()eg

控制檯日誌: 「無法加載類dijit.layout.BorderContainer」

錯誤的IE9點是在parser.js(道場釋放-1.7.2-SRC)的線132:

darray.forEach(nodes, function(obj){ 
         if(!obj){ return; } 

         var node = obj.node || obj, 
           type = dojoType in mixin ? mixin[dojoType] : obj.node ? obj.type : (node.getAttribute(dataDojoType) || node.getAttribute(dojoType)), 
           ctor = _ctorMap[type] || (_ctorMap[type] = dlang.getObject(type)), 
           proto = ctor && ctor.prototype; 
         if(!ctor){ 
     Line 132 ---> throw new Error("Could not load class '" + type); 
         } 

有沒有人對我做錯了什麼有所瞭解,如果考慮到上述代碼在IE9中完美工作時,我有parseOnLoad:true?

由於

+0

你的data-dojo-config屬性是什麼樣的?需求聲明和回調是什麼樣的? – BuffaloBuffalo

+0

不知道更多的HTML內容 - 我敢打賭,這個問題是DOCTYPE相關的,並回落到各種怪癖模式(解釋不同的行爲和瀏覽器)。但問題是'原子'類加載 - 需要按正確的順序排序。解析器在所有需要的模塊被拉入之前無法運行。 – mschr

回答

0

用99%的確定性,誤差是由於dlang.getObject(type)返回空指針。我的猜測是AMD加載器(可能設置爲async:true)尚未完成錯誤中提到的模塊的下載和聲明。爲了克服這個問題,你必須適應需求拉動的AMD模式 - 並且一旦準備就緒(每個需要的模塊)就會運行。嘗試如下包裝您的parser.parse():

<script src="path_to_dj/dojo/dojo.js"></script> 
<!-- dojo must be loaded first - obviously --> 
<script type="text/javascript"> 

    require(
    {/*using defaults*/},   /* local conf */ 
    [        /* every single requirement, mapped to cb params below */ 
     "dijit/layout/BorderContainer", 
     "dijit/layout/TabContainer" 
     // optionally uncomment below line to have callback wait domReady event 
     //, "dojo/domReady!" 
    ], 
    function(dep1, dep2, dep3) { /* callback for XHR.readyState=4/SCRIPT.onload */ 

      parser.parse(dojo.body()); 

    } 
); 

</script> 
+0

感謝大家的建議。這個問題通過在腳本塊中要求解決,我調用parser.parse(),解析器必須在中處理所有模塊。看起來IE需要它,但其他瀏覽器可以「使用」來自我使用它們的其他腳本塊的模塊。因此,您必須加載解析器需要在腳本塊中解析的所有模塊,您要調用解析() – Redg

+0

就像它在答案中所說的那樣? :p – mschr