-2

我正在我的基于 angularjs 的应用程序中实现 angular 数据表,我正在做休息服务调用并获取对象列表作为对 angularjs 控制器的响应,例如

roomCategories.fetch({}, function(list){
            $scope.categories = list.list;
        });

在这个范围内,我将获得对象列表,我需要在角度数据表中设置范围 var。但是当我尝试实现为

$scope.dtOptions = DTOptionsBuilder.fromFnPromise($scope.categories)
    .withPaginationType('full_numbers');
    $scope.dtColumnDefs = [
        DTColumnDefBuilder.newColumnDef(0).withTitle('Name'),
        DTColumnDefBuilder.newColumnDef(1).withTitle('Description')
      ];

我已经看到解释了json或数组实现之类的示例,但是我需要添加或设置范围变量,即数据表中的列表。

在我的 html 代码中

<table datatable dt-options="dtOptions" dt-column-defs="dtColumnDefs"></table>

但是数据没有反映在页面中,谁能帮我解决这个问题。

4

1 回答 1

0

我认为你可以这样做:

    <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="row in yourData">
            <td>{{row.id}}</td>
            <td>{{row.firstName}}</td>
            <td>{{row.lastName}}</td>
        </tr>
        </tbody>
    </table>
</div>

希望能帮助到你。

于 2016-04-05T15:53:29.077 回答