如何在两个ng-repeat指令中使用不同的数据?

时间:2015-11-05 08:13:34

标签: angularjs

我试图制作一个可编辑的表格指令。我有两个配置:

1)表格配置:

table = [
            {name: 'id',title: '#'},
            {name: 'name',title: 'Name'}, 
            {name: 'phone',title: 'Phone'}, 
            {   
                name: 'action',
                title: 'Edit',
                button_name: 'Edit me',
                type: 'button',
            }
];

2)数据配置:

  data = [
  {id: 1, name: 'Rikki', phone: 02},
  {id: 2, name: 'Pikki', phone: 03},
  {id: 3, name: 'Mikki', phone: 03}
];

我想知道,当按钮操作时,如何将按钮放在单元格中。行:

3)HTML:



<thead>
     <tr>
        <h2>head</h2>
        <td ng-repeat="(key, value) in table">{{value.title}}</td>
     </tr>
</thead>
<tbody>
     <tr ng-repeat="(tkey, dataValue) in data">
       <td ng-repeat="(dkey, value) in dataValue">
         {{value}}  // and if it's 'Action' column, I want to push data from Table config to show buttons
&#13;
&#13;
&#13;

有可能吗?谁能帮帮我?

1 个答案:

答案 0 :(得分:0)

<thead>
     <tr>
        <th ng-repeat="column in table">{{ column.title }}</th>
     </tr>
</thead>
<tbody>
     <tr ng-repeat="row in data">
         <td ng-repeat="column in table">
             <span ng-if="column.name !== 'action'">
                 {{ row[column.name] }}
             </span>
             <span ng-if="column.name === 'action'">
                 <button>{{ column.button_name }}</button>
             </span>
         </td>
     </tr>
</tbody>