Angularjs,表中单行中的两个数据

时间:2014-08-27 13:19:54

标签: html angularjs ng-repeat

我有一个问题来实现宽度很薄的表。

myData = { name:"Foo", age:11, sex:"M", weight:77, height:77, hobby:'gaming'}

我想像下面一样表。

<table>
    <tr>
       <td>name</td><td>Foo</td><td>age</td><td>11</td>
    </tr>
    <tr>
       <td>sex</td><td>M</td><td>weight</td><td>77</td>
    </tr>
    <tr>
       <td>height</td><td>77</td><td>hobby</td><td>gaming</td>
    </tr>
</table>

是否可以使用ngRepeat及其内置变量显示这样的数据?

2 个答案:

答案 0 :(得分:1)

John发布的问题可以解决您的问题,但我认为使用ng-repeat-startng-repeat-end就不那么糟糕了:

<table>
    <tr ng-repeat-start="item in myData">
       <td>name</td><td>{{item.name}}</td><td>age</td><td>{{item.age}}</td>
    </tr>
    <tr>
       <td>sex</td><td>{{item.sex}}</td><td>weight</td><td>{{item.weight}}</td>
    </tr>
    <tr ng-repeat-end>
       <td>height</td><td>{{item.height}}</td><td>hobby</td><td>{{item.hobby}}</td>
    </tr>
</table>

答案 1 :(得分:-1)

如果您的myData是这样的:

myData = [{ name:"Foo", age:11, sex:"M", weight:77, height:77, hobby:'gaming'},{ name:"Foo", age:11, sex:"M", weight:77, height:77, hobby:'gaming'},{ name:"Foo", age:11, sex:"M", weight:77, height:77, hobby:'gaming'}]

然后你的桌子会是这样的:

<table>
   <tr ng-repeat="row in myData">
      <td>{{row.name}}</td>
      <td>{{row.age}}</td>
      <td>{{row.sex}}</td>
      <td>{{row.weight}}</td>
      <td>{{row.height}}</td>
      <td>{{row.hobby}}</td>
   </tr>
</table>