2011-06-08 69 views
1

我使用jQote作爲我的頁面的模板系統。我很難解釋文字中發生了什麼,所以我上傳了一段視頻。jqote模板問題與jquery ui選項卡(視頻內)

http://www.youtube.com/watch?v=ugw4lIsF0HM

基本上有些時候它呈現的權利,有時它不喜歡有錯誤。 Chrome和Firefox不會報告錯誤,當我使用Chrome進行檢查時,如果輸出不正確,或輸出正確,則輸出相同。

這是我的代碼。

<script type="text/javascript"> 

    $.getJSON('/json/testData', function(data) { 
     $('#reportDiv').prepend($('#template').jqote(data));  
     // $('#reportDiv').html($.jqote('#template', data)); 
    });  

</script> 

<div id="pkgLineTabs" style="font-style: inherit; font-size: 13px" > 
    <div id="reportDiv"></div> 
</div> 

<script type="text/x-jqote-template" id="template"> 
    <![CDATA[ 
    <ul> 
     <% for (i = 0; i <= data.length; i++) { %> 
     <li><a href="#pkgLineTabs_<%= this.data[i].hash %>" class="toolTip" id="<%= this.data[i].hash %>"><%= this.data[i].shortname %></a></li> 
     <% } %> 
    </ul> 

    ]]> 
</script> 

我試過了我能想到的一切。我將文件從頭部移動到頁面底部。更改了訂單。我不確定發生了什麼事。

這是我的json,任何需要查看它的人。

{"data":[{"hash":"FB900DF","shortname":"Lines 3 & 4 - Baltimore"},{"hash":"FBAE86D","shortname":"Line 1 Cans"}]} 

我不知道有沒有人見過這個。由於$ {字符,我無法切換到jquery模板。 Play框架不喜歡那樣。

我有一種感覺,這與$ .getJSON調用有關,因爲如果我使用setTimeout函數並將其設置爲1或10,它永遠不會正確完成。

感謝您的任何幫助。

編輯:

<script type="text/x-jqote-template" id="template"> 
<![CDATA[ 
<ul> 
    <% for (i = 0; i <= data.length; i++) { %> 
    <li><a href="#pkgLineTabs_<%= this.data[i].hash %>" class="toolTip" id="<%= this.data[i].hash %>"><%= this.data[i].shortname %></a></li> 
    <% } %> 
</ul> 
<% for (i = 0; i <= data.length; i++) { %> 
<div id="pkgLineTabs_<%= this.data[i].hash %>"> 
    <table class="reportTable display" style="font-size:13px" title="<%= this.data[i].hash %>" > 
     <thead> 
      <tr> 
       <th style="">Row Color</th> <!--hidden --> 
       <th style="">Time Stamp</th> 
       <th style="">Ounces</th> 
       <th style="">Revolutions</th> 
       <th style="">Pallet Count</th> 
       <th style="">Roll Change</th> 
       <th style="">Breaks</th>     
      </tr> 
     </thead> 
     <tbody> 
      <tr> 
       <td colspan="5" class="dataTables_empty">Loading data from server...</td> 
      </tr> 
     </tbody> 
    </table> 
</div> 
<% } %> 
]]> 

這是一個完整的代碼。

這是我的數據表功能

$(window).load(function() {   

    $('.reportTable').each(function() {  

     var pkgLineId = $(this).attr('title'); 

     var reportTable = $(this).dataTable({   

      "bJQueryUI": true, 
      "sPaginationType": "full_numbers", 
      "bPaginate": true, 
      "bLengthChange": true, 
      "bFilter": false, 
      "bSort": false, 
      "bInfo": true, 
      "bAutoWidth": false,  
      "bProcessing": true, 
      "bServerSide": true, 
      "bProcessing": true, 
      "sDom": '<"H"lfrp>t<"F"lip>', 
      "iDisplayLength": 15, 
      "aLengthMenu": [[10, 15, 20, 50, 100, 200, 500], [10, 15, 20, 50, 100, 200, 500]], 
      "aoColumns": [ 
      { 
       "bVisible": false 
      },   
      null, 
      null, 
      null,     
      null, 
      null, 
      null  
      ], 
      "sAjaxSource": '/json/reportData/'+pkgLineId, 
      "fnDrawCallback": function() { 

       var nodes = reportTable.fnGetNodes(); 
       var lineStatus; 
       for (var i = 0; i < nodes.length; i++) {     
        lineStatus = reportTable.fnGetData(nodes[i]);    
        nodes[i].setAttribute("style", "background: " + lineStatus[0]);     
       } 
      }   
     }); 
    }); 

}); 

我試圖把這個在$ .getJSON完整的()函數,但事實是它需要的window.load,因爲它是相當多的數據。我可能錯過了一些東西。

我的數據表會觸發一段時間。有時它只是掛起而沒有任何反應。

+0

+1視頻。幫助瞭解很多 – Niklas 2011-06-08 19:24:40

回答

1

隨着你已經顯示的代碼,你究竟在哪裏啓動標籤?因爲從外觀上看,在啓動選項卡之前,您並沒有檢查json請求是否已完成,如果是這種情況,那麼您得到的結果並不令人意外(假設您目前是本地的,何時你可以將它移動到互聯網,你可能不會讓它工作一次)。

試試這個,編輯以下:

$.getJSON('/json/testData', function(data) { 
     $('#reportDiv').prepend($('#template').jqote(data));  
     // $('#reportDiv').html($.jqote('#template', data)); 
    }); 

要的地方包括:啓動選項卡,這樣的部分:

$.getJSON('/json/testData', function(data) { 
     $('#reportDiv').prepend($('#template').jqote(data));  
     // $('#reportDiv').html($.jqote('#template', data)); 
     $("#pkgLineTabs").tabs(); //and whatever settings you have for it currently, i.e. move it here 
    }); 
+0

這是我的錯,因爲沒有指明我已經嘗試過。這工作,但它保持我的數據表加載在選項卡內。我試圖簡化我的代碼和問題,因爲我認爲它可能植根於相同的問題。如果我們不能得出結論,我會給你答案的,因爲你實際上回答了我的問題。這是我沒有說明的錯。 現在我要更新我的問題,看看我們從那裏得到什麼。 – 2011-06-08 19:31:47

+0

我已將編輯添加到我的問題中。這可能是一些簡單的,我錯過了window.load函數和我的$ .getJSON方法。它可能只是需要把它們放在同一個window.load函數中(我還沒有嘗試過) – 2011-06-08 19:35:09

+0

@Drew H.讓我們來看看它的其餘部分,然後你仍然沒有提供代碼在哪裏啓動選項卡然而,從外觀上看,你和dataTables有同樣的問題,就像你使用tab一樣。在啓動選項卡的地方啓動同樣的json函數中的dataTables,看看它是否有效。 – Niklas 2011-06-08 19:37:45