2012-03-01 11 views
0

JSONは次のようになります。どのように配列をソートし、HTMLでそれぞれをラップするのですか?

[{"title":"Modern\/Contemporary House of mine.","link":"http:\/\/buildworx-mc.com\/forum\/showthread.php?tid=1718","images":["http:\/\/i1139.photobucket.com\/albums\/n555\/xDJBOUTIx\/house1.png","http:\/\/i1139.photobucket.com\/albums\/n555\/xDJBOUTIx\/House2.png","http:\/\/i1139.photobucket.com\/albums\/n555\/xDJBOUTIx\/House3.png","http:\/\/i1139.photobucket.com\/albums\/n555\/xDJBOUTIx\/House4.png","http:\/\/i1139.photobucket.com\/albums\/n555\/xDJBOUTIx\/House5.png","http:\/\/i1139.photobucket.com\/albums\/n555\/xDJBOUTIx\/House6.png"]} 

私はタイトルとうまくリンクを得ることができます。しかし、いくつかは複数のリンクがあるため、画像を取得できません。

enter image description here

私は、それぞれの画像がHTMLでラップされるリンクを取得しようとしています。

$.getJSON("gallery/getScreenshots.php", function (data) { 
    $.each(data, function (i, image) { 
     var link = image.link, title = image.title. images = image.images; 

    $img = $('<img>').attr('src', images); 
    $('#screenshots').append($img); 

    }); 

しかし、結果はこれです:

<img src="http://i1139.photobucket.com/albums/n555/xDJBOUTIx/house1.png,http://i1139.photobucket.com/albums/n555/xDJBOUTIx/House2.png,http://i1139.photobucket.com/albums/n555/xDJBOUTIx/House3.png,http://i1139.photobucket.com/albums/n555/xDJBOUTIx/House4.png,http://i1139.photobucket.com/albums/n555/xDJBOUTIx/House5.png,http://i1139.photobucket.com/albums/n555/xDJBOUTIx/House6.png" alt=""> 

どのようにソート配列を通って、各画像は$.eachループを使用して<img>?

答えて

2

に追加してもらうことができます:

$.each(images, function(i,el) { 
    $('#screenshots').append($('<img>',{'src',el})); 
}); 
+0

私はあなたを使用し、私がキャッチされないでSyntaxErrorを得る:予期しないトークン、 – nowayyy

+0

は実際に気にしない、あなたに感謝! – nowayyy

0

地獄トリピー、

これは以下のコードと作業デモhereです。

var info=[ 
    { 
     "title": "Modern/Contemporary House of mine.", 
     "link": "http://buildworx-mc.com/forum/showthread.php?tid=1718", 
     "images": [ 
      "http://i1139.photobucket.com/albums/n555/xDJBOUTIx/house1.png", 
      "http://i1139.photobucket.com/albums/n555/xDJBOUTIx/House2.png", 
      "http://i1139.photobucket.com/albums/n555/xDJBOUTIx/House3.png", 
      "http://i1139.photobucket.com/albums/n555/xDJBOUTIx/House4.png", 
      "http://i1139.photobucket.com/albums/n555/xDJBOUTIx/House5.png", 
      "http://i1139.photobucket.com/albums/n555/xDJBOUTIx/House6.png" 
     ] 
    } 
]; 
var album=info[0]["images"]; 
for(i=0;i<album.length;i++) 
{ console.log(album[i]); 
    $('#screenshots').append($('<img>').attr('src', album[i])          
         .css({'width':'200px','height':200px'})); 
} 

関連する問題