开发者

Jquery - Multi array and each

开发者 https://www.devze.com 2023-01-15 23:35 出处:网络
i have a problem with the each function. HTML <div id=\"d1\" class=\"line1\"></div> JS $(function() {

i have a problem with the each function.

HTML

<div id="d1" class="line1"></div>

JS

$(function() {


tt = new Array();
tt['id_32'] = new Array("32", "gudfgws", "htdfgss", "0", "gudfgdgf开发者_开发技巧s", "0", "halder", "0");  
tt['id_35'] = new Array("35", "TVdfg.xml", "154", "Was läuft jetzt im TV", "0", "simpsons", "0");
tt['id_36'] = new Array("36", "Gddfge", "httdfg0", "155", "Idfgs", "0", "apple", "0");

   $.each(tt, function(key1,key2)
   {             
       $('#d1').append('-> '+key1+' - '+key2+' <br />');                 
  });

});

I dont get anything ... no error and no results. Can anybody tell me where the bug is?

Working example http://www.jsfiddle.net/V9Euk/558/

Thanks in advance! Peter


You're using named indexes with an array which doesn't work, you need tt to be an object instead, like this:

var tt = {};

Here's the updated/working version.


$(function() {
    tt = {} //Object
    tt.id_32 = new Array("32", "gudfgws", "htdfgss", "0", "gudfgdgfs", "0", "halder", "0");  
    tt.id_35 = new Array("35", "TVdfg.xml", "154", "Was läuft jetzt im TV", "0", "simpsons", "0");
    tt.id_36 = new Array("36", "Gddfge", "httdfg0", "155", "Idfgs", "0", "apple", "0");

    $.each(tt,function(_key,_array){
       $.each(_array,function(value){
           $('#d1').append('-> '+_key+' - '+value+' <br />')
       });
    })
});

Give that a go for me.

0

精彩评论

暂无评论...
验证码 换一张
取 消