2

How can I fill in the following table html structure with json data in a dynamic way? (with AngularJS).

Here is the basic HTML structure:

<table class="some styling">
                    <tbody>
  <tr>
    <td><a title="test" href="#"><span>Just some tests</span></a></td>
    <td><a title="test" href="#"><span>Just some tests</span></a></td>
    <td><a title="test" href="#"><span>Just some tests</span></a></td>
  </tr>
  <tr>
  <td><a title="test" href="#"><span>Just some tests</span></a></td>
  <td><a title="test" href="#"><span>Just some tests</span></a></td>
  <td><a title="test" href="#"><span>Just some tests</span></a></td>
  </tr>
 </tbody>
</table>

The difficult part is how to determine the "tr" elements. There are always 3 td elements in 1 tr element. Only the amount of TD elements may vary.

Thanks in advance

4
  • Which code have you written in angular ? show your json Commented Jul 6, 2016 at 7:33
  • Are you looking for ng-repeat? It very much depends how your JSON / Array looks like. Commented Jul 6, 2016 at 7:35
  • And yes I know I should use "ng-repeat" but I don't know how I can provide dynamic rows Commented Jul 6, 2016 at 7:55
  • dynamic rows will be craeated based on json data. you can use ng-repeat i will post the example for this Commented Jul 6, 2016 at 8:30

1 Answer 1

1
Html:
<table border="1" style="border-collapse: collapse">
      <tr>
        <th>id</th>
         <th>firstname</th>
          <th>lastname</th>
      </tr>
      <tr ng-repeat="user in users">
        <td>{{user.id}}</td>
        <td>{{user.firstname}}</td>
        <td>{{user.lastname}}</td>
        </tr>
    </table>  

Json:

$scope.users=[
    {id:1,firstname:"naresh",lastname:"kumar"},
    {id:2,firstname:"suresh",lastname:"kumar"},
    {id:3,firstname:"harish",lastname:"kumar"},
    ]

this is the example am posting you can manipulate it. you can a have look here https://plnkr.co/edit/umC2hwECePaAqZ0huYoK?p=preview

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks for your answer. I understand your example but in my case it's different. I don't need different values likes id,firstname,lastname. I have to show only the site's name. I thought something like this: <tr ng-repeat="item in navigationData"> <td><span>{{navigationData[$index].name}}</span></td> <td><span>{{navigationData[$index+1].name}}</span></td> <td><span>{{navigationData[$index+2].name}}</span></td> </tr> But it still does not work..
So I need something like this: (example) '[SiteA][SiteB][SiteC] [SiteAA][SiteBB][SiteCC] [SiteAAA][SiteBBB][SiteCCC]' ... Always 3 columns but different rows

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.