javascript - Obtain data from Json using angular -


below code:

post.json

[     {         "client_id":"100",         "client_name":"mm hope house",         "user_fname":"betty",         "user_lname":"johnson",         "user_id":"10",         "username":"bjohnson",         "total_web":"$500",         "campaigns":{             "campaign":[{                 "id":"23",                 "campaign_name":"mm hope house",                 "start_date":"4/15/2015",                 "end_date":"6/13/2015",                 "goal":"$20,000",                 "total_pledges":"$1550",                 "total_donations":"$1000"             }],             "pledgees":[{                 "pledgee_fname":"tavonia",                 "pledgee_lname":"evans",                 "pledge_email":"tavonia@gmail.com",                 "pledge_date":"4/22/2015",                 "pledge_amount":"$50.00",                 "paid":"$50.00",                 "last_pledge":"$50.00"             }],             "donors":[{                 "donor_fname":"pat",                 "donor_lname":"smith",                 "donor_email":"patsmith@onlinemediainteractive.com",                 "total_cdonation":"$10.00",                 "total_ldonation":"$450.00",                 "last_donation":"$200.00",                 "last_pledge":"$350.00"             }]         }     } ] 

my html code:

<script>      function postsctrlajax($scope, $http) {          $http({method: 'post', url: 'assets/js/posts.json'})             .success(function(data) {                  console.log(data);                  $scope.posts = data;             })             .error(function(data, status) {                  $scope.posts = data || "request failed";             });     }  </script> 

my html code want populate data:

<thead>   <tr>     <th>campaign id</th>     <th>first name</th>     <th>last name</th>     <th>amount</th>     <th>email id.</th>     <th>pledge date</th> </tr> </thead>  <tbody>     <tr ng-repeat="post in posts" >     <td>{{post.id}}</td>     <td>{{post.pledgee_fname}}</td>     <td>{{post.pledgee_lname}}</td>     <td>{{post.pledge_amount}}</td>     <td>{{post.pledge_email}}</td>     <td>{{post.pledge_date}}</td> 

i trying client_id pleg_fname array, not know how to.

your pledgess object array of objects should instead , entire json contained within array need first element entire object , call posts[0] , specify object trying iterate : pledgees.

<tr ng-repeat="post in posts[0].campaigns.pledgees" >   <td>{{posts[0].campaigns.campaign[0].id}}</td>   <td>{{post.pledgee_fname}}</td>   <td>{{post.pledgee_lname}}</td>   <td>{{post.pledge_amount}}</td>   <td>{{post.pledge_email}}</td>   <td>{{post.pledge_date}}</td> 

edit

you're right, totally missed array. see plunker tested http://plnkr.co/edit/dvdnjv2mn2gljqgi9lls?p=preview

edit 2

if want campaign id add (updated original code change)

{{posts[0].campaigns.campaign[0].id}} 

Comments

Popular posts from this blog

c# - Validate object ID from GET to POST -

node.js - Custom Model Validator SailsJS -

php - Find a regex to take part of Email -