2013-04-05 213 views
4

IE8支持財產或SCRIPT438:對象不支持屬性或方法 '的forEach'

$('.tabs').tabs(); 
$('#search-consumables [data-ajax-call]').change(function() { 

    var $this = $(this), 
     settings = $this.data(), 
     $target = $(settings.target); 

    $.ajax({ 
     type: 'GET', 
     url: 'index.php?route=module/quicklookup/' + settings.ajaxCall, 
     data: $this.closest('form').serializeArray(), 
     dataType: 'json', 
     success: function(data) { 
      var html = ''; 
      $target.find(':not(.blank)').remove(); 
      html = $target.html(); 
      data.forEach(function(entry) { 
       html += '<option value="'+entry.id+'">'+entry.name+'</option>'; 
      }); 
      $target.html(html); 
     } 
    }); 
}); 

我已經試過

$.each(data, function(entry) { 

但數據然後返回未定義的方法 '的forEach',我是什麼想要在IE8中工作?

+0

'data'是類型'object'它沒有方法'的foreach()' – jmoerdyk 2013-04-05 21:29:24

回答

6

傳遞給jQuery.each回調函數的第一個參數是數組中值的索引;第二個參數是實際值。

嘗試使用:

$.each(data, function(i, entry) { 
    // your code here 
}); 
+0

這是偉大的,謝謝! – user2250678 2013-04-05 22:08:43

相關問題