2016-09-13 5 views
1

でJSONでサブネストされたオブジェクトの値へのアクセス:私は結果のサブ配列オブジェクトにアクセス値をしようとしている角度

results: [ 
{ 
    list_name: "E-Book Fiction", 
    display_name: "E-Book Fiction", 
    bestsellers_date: "2016-09-03", 
    published_date: "2016-09-18", 
    rank: 1, 
    rank_last_week: 0, 
    weeks_on_list: 1, 
    asterisk: 0, 
    dagger: 0, 
    amazon_product_url: "http://rads.stackoverflow.com/amzn/click/1250022134", 
isbns: [], 
    book_details: [ 
    { 
     title: "A GREAT RECKONING", 
     description: "An instructor at the police academy is found murdered, perhaps by one of the cadets favored by Armand Gamache, the retired homicide chief of the Sûreté du Québec.", 
     contributor: "by Louise Penny", 
     author: "Louise Penny", 
     contributor_note: "", 
     price: 0, 
     age_group: "", 
     publisher: "Minotaur", 
     primary_isbn13: "9781250022127", 
     primary_isbn10: "1250022126" 
    } 
    ], 
    reviews: [ 
    { 
     book_review_link: "", 
     first_chapter_link: "", 
     sunday_review_link: "", 
     article_chapter_link: "" 
    } 
] 
} 

私はbook_detailsからtitleのような値をつかむが、現在のみ表示することができるように、全体の応答:

myBooks.controller('bookController', function($scope, $http){ 
    $http.get("data-url") 
    .success(function(response) { 
     console.log(response); 
     $scope.results = response; 
    }); 
}); 
01:

<article class="search-result row" ng-repeat="books in results"> 
     <div class="col-xs-12 col-sm-12 col-md-3"> 
      {{books}} 
     </div> 
</article> 

私のコントローラは、単に結果をつかん、非常に簡単です

Webコンソールでのオブジェクトのスクリーンショット:

enter image description here

+0

反復します。 –

答えて

-1

あなたはこのようにそれを書くことができます。結果配列を反復処理することによって、スコープ内に新しいブック配列を作成します。書籍の詳細ではない結果にオーバー

app.controller("MyController", ["$scope","$http", 
function($scope, $http) { 

     $scope.books; 

     $http.get('test.json').then(function (response){ 
       console.log(response.data.results); 
      $scope.results = response.data.results; 
      $scope.results.map(function(obj, index) { 
       if(obj.book_details) { 
       if(!($scope.books)) { 
        $scope.books = []; 
       } 
       for(var i in obj.book_details) { 
        $scope.books.push(obj.book_details[i]); 
       } 
       } 
      }); 

      console.log($scope.books); 
    });     

}]); 

<article class="search-result row" ng-repeat="book in "> 
    <div class="col-xs-12 col-sm-12 col-md-3"> 
     {{book.title}} 
    </div> 
</article> 

Working link

+0

これは何の影響もありません。 – user3438917

+0

ビューに正確に表示したいものは何ですか? –

+0

タイトル:A Great Reckoningを出力できるはずです。 Webコンソールにオブジェクトのスクリーンショットを添付しました。 – user3438917

関連する問題