2016-12-13 27 views
0

我是新来角,我有一个页面,将使用dtable。该表将建立在我的控制器,但暂时我想添加一些硬编码行,直到我准备好填充我的表与有效的细节,但我不知道如何做到这一点。将硬编码行添加到AngularJS表选项

HTML

<dtable class="full-height material" 
     style="height: 555px" 
     options="vm.tableoptions" 
     rows="vm.adviseraccess"> 
</dtable> 

控制器

var vm = this; 
    vm.tableoptions = 
    { 
     rowHeight: 50, 
     headerHeight: 30, 
     footerHeight: 50, 
     columnMode: 'force', 
     columns: 
     [ 
      { 
       name: "Adviser Name", 
       width: 75 
      }, 
      { 
       name: "Allow Access", 
       width: 25 
      } 
     ], 
    }; 

我想看看能否加入itemstableoptions会工作,如下图所示,但它不会

vm.tableoptions = 
    { 
     rowHeight: 50, 
     headerHeight: 30, 
     footerHeight: 50, 
     columnMode: 'force', 
     columns: 
     [ 
      { 
       name: "Adviser Name", 

       width: 75 
      }, 
      { 
       name: "Allow Access", 

       width: 25 
      } 
     ], 
     items: 
     [ 
      { 
       "name": "One" 
      } 
      { 
       "name": "Two" 
      } 
     ] 
    }; 

而且我也试过以下

vm.adviseraccess = [ 
     { 
      name: "Antony" 
     }, 
     { 
      name: "Bob" 
     }, 
     { 
      name: "Will" 
     } 
    ]; 

回答

1

尝试像这样

<div ng-controller="AngularWayCtrl as showCase"> 
    <table datatable="ng" class="row-border hover"> 
     <thead> 
     <tr> 
      <th>ID</th> 
      <th>FirstName</th> 
      <th>LastName</th> 
     </tr> 
     </thead> 
     <tbody> 
     <tr ng-repeat="person in showCase.persons"> 
      <td>{{ person.id }}</td> 
      <td>{{ person.firstName }}</td> 
      <td>{{ person.lastName }}</td> 
     </tr> 
     </tbody> 
    </table> 
</div> 

Controller 

angular.module('showcase.angularWay', ['datatables', 'ngResource']) 
.controller('AngularWayCtrl', AngularWayCtrl); 

function AngularWayCtrl($resource) { 
var vm = this; 
vm.persons=[{ 
    "id": 860, 
    "firstName": "Superman", 
    "lastName": "Yoda" 
}, { 
    "id": 870, 
    "firstName": "Foo", 
    "lastName": "Whateveryournameis" 
}, { 
    "id": 590, 
    "firstName": "Toto", 
    "lastName": "Titi" 
}, { 
    "id": 803, 
    "firstName": "Luke", 
    "lastName": "Kyle" 
}]; 
} 

更多详情,请参阅此链接Angular-dataTables