2013-02-28 111 views
1

我構建了一個智能數據網格,其中包含將識別(模糊)它們是否發生更改以及值是否升高或降低的單元格。我的jQuery似乎沒有與Wijmo Grid一起工作

下面是它的樣子。當用戶懸停一個已更改的框並顯示頁面第一次加載時的值時,會出現灰色的工具提示。


enter image description here


我想將其轉換爲一個Wijmo電網,但保持相同的上/下的腳本,以顯示何時以及如何值的變化。但是,當我將表格初始化爲Wijmo網格時,突然我的腳本在所有瀏覽器中停止工作

問題:爲什麼會發生這種情況,是否有簡單的解決方法?你能不能用傳統的jQuery和Javascript訪問Wijmo單元格?

部分HTML代碼(Full code and working example without Widjmo here):

<table id="data-grid"> 
    <thead> 
     <tr> 
      <th>March</th> 
      <th>April</th> 
      <th>May</th> 
     </tr> 
    </thead> 
    <tbody> 
     <tr> 
      <td><input type="text" value="12000" /></td> 
      <td><input type="text" value="1000" /></td> 
      <td><input type="text" value="100000" /></td> 
     </tr> 

這裏是我當前的jQuery代碼(Full code and working example without Widjmo here):

$(function() { 
    // Initializes data grid as a Widjmo Grid (currently commented out) 
    //$("#data-grid").wijgrid(); 

    // Array to store the initial values in grid 
    var initialValues = []; 

    // Assigns an index ID to each cell in the grid 
    $('input').each(function(index) { 
     initialValues[index] = $(this).val(); 
     $(this).data('id', index); 
    }); 

    // Checks cell(s) for changes on blur (lose focus) 
    $("input").blur(function() { 
     var $t = parseInt($(this).val(), 10); 
     var $s = parseInt(initialValues[$(this).data('id')], 10); 

     // Value has changed 
     if($t != $s) { 
      var sign = ""; 
      if($t-$s > 0) { 
       sign="+"; 
      } 
      $(this).parent().children(".tooltip").remove(); 
      $(this).parent().append("<div class='tooltip'>Initial " + $s + "<br/>Change " + sign + ($t-$s) + "</div>"); 
     } 

     // Value is no different from intial value 
     if($t == $s) { 
      $(this).removeClass("up down"); 
      $(this).parent().children(".tooltip").remove(); 
      $(this).parent().children(".up-indicator, .down-indicator").remove(); 
     } 

     // Value is greater than initial 
     else if($t > $s) { 
      $(this).removeClass("up down"); 
      $(this).parent().children(".up-indicator, .down-indicator").remove(); 
      $(this).addClass("up"); 
      $(this).parent().append("<div class='up-indicator'></div>"); 
     } 

     // Value is less than initial 
     else if($t < $s) { 
      $(this).removeClass("up down"); 
      $(this).parent().children(".up-indicator, .down-indicator").remove(); 
      $(this).addClass("down"); 
      $(this).parent().append("<div class='down-indicator'></div>"); 
     } 

     // Conpute the net change 
     netChange(initialValues); 
    }); 

    // Displays tooltip of changed items 
    $("input").hover(function() { 
     $(this).parent().children(".tooltip").toggle(); 
    }); 

    // Computes the net change in the data grid 
    function netChange(initialValues) { 
     var runningTotal = 0; 
     $('input').each(function() { 
      runningTotal += parseInt($(this).val(), 10); 
     }); 

     var intialTotal = 0; 
     for (var i = 0; i < initialValues.length; i++) { 
      intialTotal += parseInt(initialValues[i], 10); 
     } 

     var changes = $(".up, .down").length; 

     $("#items").text(changes + " Items"); 
     $("#net").text("Net: " + (runningTotal - intialTotal)); 
    } 
}); 
+0

您使用的瀏覽器是? – Dom 2013-03-12 18:40:25

+0

Chrome版本25.0 [.1364.152] – Jon 2013-03-12 18:46:38

回答

1

的Wijmo插件代碼使用$.browser.msie在他們的代碼是已棄用在jQuery 1.3中,並在jQuery 1.9中完全刪除。請參閱jQuery文檔:http://api.jquery.com/jQuery.browser/及以下是加粗的評論,說明刪除它的原因。

我們建議不要使用此屬性;請嘗試改用功能檢測(請參閱jQuery.support)。 jQuery.browser可能會在未來的jQuery版本中移動到插件中。


你的代碼提示下班後有一次我在小提琴選擇了jQuery 1.8的早期版本。

固定小提琴:http://jsfiddle.net/Fgdec/13/


在你的小提琴,你已經選擇的jQuery 1.9這不有$.browser.msie,所以它在Chrome控制檯拋出下面的錯誤。

Uncaught TypeError: Cannot read property 'msie' of undefined jquery.wijmo-open.all.2.3.8.min.js:31 
(anonymous function) jquery.wijmo-open.all.2.3.8.min.js:31 
(anonymous function) jquery.wijmo-open.all.2.3.8.min.js:61 
Uncaught TypeError: Cannot read property 'msie' of undefined jquery.wijmo-complete.all.2.3.8.min.js:34 
(anonymous function) jquery.wijmo-complete.all.2.3.8.min.js:34 
(anonymous function) jquery.wijmo-complete.all.2.3.8.min.js:34 
+0

我發佈的代碼正在工作 - 我已經註釋了Wijmo初始化。如果您在jQuery中取消註釋第3行以初始化Wijmo網格,則會看到jQuery無響應。這是我遇到的問題。 – Jon 2013-03-12 20:41:40

+1

我收回它。顯然,jQuery 1.9.x是畢竟的問題。謝謝你的收穫! – Jon 2013-03-12 20:43:25