2016-08-01 3 views
0

ネストしたjsonオブジェクトにng-repeatを使用しようとしています。イオンプロジェクトのネストされたjsonでng-repeatを使用する方法

{ 
     "title": "Important message 01", 
     "img": "any url image here", 
     "authorPhoto": "http://lorempixel.com/40/40/people/4/", 
     "author": "John Doe", 
     "datePosted": "1 day ago", 
     "thumbsUp": "245", 
     "thumbsDown": "200", 
     "commentsNum": "123", 
     "id": "1", 
     "comments": [ 
      "comment", 
      { 
       "authorCommentPhoto": "http://lorempixel.com/40/40/people/5/", 
       "author": "Jimmy doe", 
       "text": "useless commment", 
       "dateCommented": "01/08/2016" 
      } 
     ] 
    } 

私はトップレベルのJSON(タイトル、IMG、など...)一覧表示することができますが、私はコメント部分、私はこの問題を解決するにはどうすればよい

<ion-item ng-repeat="card in cards" href="#/app/playlists/{{card.id}}" class="card-wrapper"> 
     <div class="card" style="background: url({{card.img}}); background-size:100%;"> 
      <div class="inner-wrapper"> 
       <img ng-src="{{card.authorPhoto}}" alt="Author profile photo"> 
       <p class="author">{{card.author}} <br> 
            {{card.datePosted}} 
       </p> 
       <p class="essay">{{card.title}}</p> 
       <div class="footWrapper"> 
        <div class="thumbsUp"><i class="icon ion-arrow-up-c"></i>{{card.thumbsUp}}</div> 
        <div class="comments">{{card.commentsNum}}</div> 
        <div class="thumbsDown"><i class="icon ion-arrow-down-c"></i>{{card.thumbsDown}}</div> 
       </div> 
      </div> 
     </div> 
     <div class="commentsWrapper"> 
      <div class="head"> 
       <img class="profilePhoto" src="http://tilomitra.com/wp-content/uploads/2014/08/avatar-cartoon.png" alt="avatar photo"> 
       <input type="text" placeholder="Write a comment..."> 
      </div> 
      <div class="commentsContainer"> 
       <ul> 
        <li ng-repeat="comment in cards.comments"> 
         {{comment.authorCommentPhoto}} <br> 
         {{comment.author}} <br> 
         {{comment.text}} <br> 
         {{comment.dateCommented}} 
        </li> 
       </ul> 
      </div> 
     </div> 
    </ion-item> 

を一覧表示する方法を知っていますか?

+0

「card.commentsのコメント」は使用しないでください。 – lossleader

+0

ええ、私は@lossleaderの前に試しましたが、うまくいきませんでした。 – vbotio

+0

あなたの最初のコメントはあなたの選択した構造に従わない「コメント」です。 – lossleader

答えて

1

コメント配列には文字列とオブジェクトがあります。文字列 "comments"を削除し、オブジェクトの配列を使用します。次に、「カード会社のコメント」を使用します。

{ 
    "comments":[ 
    { 
       "authorCommentPhoto": "http://lorempixel.com/40/40/people/5/", 
       "author": "Jimmy doe", 
       "text": "useless commment 1", 
       "dateCommented": "01/08/2016" 
    }, 
    { 
       "authorCommentPhoto": "http://lorempixel.com/40/40/people/5/", 
       "author": "Jimmy doe", 
       "text": "useless commment 2", 
       "dateCommented": "01/09/2016" 
    } 
    ] 
} 
+0

は完璧に機能しました!どうもありがとうございます! – vbotio

関連する問題