开发者

JSON only returning one record

开发者 https://www.devze.com 2023-03-10 05:07 出处:网络
There are hundreds of records when I do this but I can\'t add any other info: function(data){ $.each(data.products, function(i,item){

There are hundreds of records when I do this but I can't add any other info:

function(data){

       $.each(data.products, function(i,item){   

         $("<img>").attr("src", item.imag开发者_开发问答eUrl).appendTo("#pear");   

         if ( i == 100 ) return false;   

       });   

     }); 

But when I use this I only get one record:

    function(data){   

       $.each(data.products, function(i,item){   

         $("#images").html("<li><a href='"+item.pUrl+"'><img src='"+item.iUrl+"'></a>"+"<br>"+item.Name+"<br>"+"$"+item.salePrice+"</li>");  

         if ( i == 100 ) return false;   

       });   

     }); 

Can somene please explainto me what I am doing wrong - very new to this. Thanks


Right now the bottom code replaces all code in #images

I think this would be better

function(data){   

   $.each(data.products, function(i,item){   

     $("#images").append("<li><a href='"+item.pUrl+"'><img src='"+item.iUrl+"'></a>"+"<br>"+item.Name+"<br>"+"$"+item.salePrice+"</li>");  

     if ( i == 100 ) return false;   

   });   

 }); 
0

精彩评论

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