AngularJS-Promatable与Promise的问题

时间:2016-06-01 18:52:25

标签: javascript angularjs

我正在使用https://l-lin.github.io/angular-datatables/#/dataReloadWithPromise

问题在于我无法实现重新加载/加载数据。我没有收到任何错误,但它声明表中没有数据显示。

控制器

defaultApp.controller('WebIntegrationController', ['$scope', '$sce', '$rootScope', '$anchorScroll', '$timeout', 'WebIntegrationService', 'DTOptionsBuilder', 'DTColumnBuilder', function ($scope, $sce, $rootScope, $anchorScroll, $timeout, WebIntegrationService, DTOptionsBuilder, DTColumnBuilder) {

    this.pushList = [];
    this.dtOptions = DTOptionsBuilder.fromFnPromise(function() {
        return WebIntegrationService.getPushList();
    }).withBootstrap();
    this.dtColumns = [
        DTColumnBuilder.newColumn('ProductNumber').withTitle('Product Number').withClass('text-danger'),
        DTColumnBuilder.newColumn('UserRequested').withTitle('Created By'),
        DTColumnBuilder.newColumn('TimeStamp').withTitle('Entry Date')
    ];
    this.dtInstance = {};
}]);

服务

defaultApp.factory('WebIntegrationService', ['$http', '$q', function ($http, $q) {
    return {
        getPushList: function () {
            return $http.get('/web/getpushlist');
        },
    }
}]);

前端

<div class="container-fluid gray-bg" ng-controller="WebIntegrationController as wiCtrl">
    <table datatable="" dt-options="wiCtrl.dtOptions" dt-columns="wiCtrl.dtColumns" dt-instance="wiCtrl.dtInstance" class="table table-striped table-bordered"></table>
</div>

/ web / getpushlist中的JSON

[{"ProductNumber":"AK-19B","UserRequested":"Ya Wang","TimeStamp":"06/01/2016 01:00 PM"},{"ProductNumber":"BTC-24","UserRequested":"Ya Wang","TimeStamp":"06/01/2016 01:00 PM"}]

返回承诺的$ http参考

  

$ http服务是一个函数,它接受一个参数 - 一个配置对象 - 用于生成HTTP请求并返回一个promise。

1 个答案:

答案 0 :(得分:0)

缺少一个小部分

 this.dtOptions = DTOptionsBuilder.fromFnPromise(function () {
    return WebIntegrationService.getPushList();
}).withBootstrap().withDataProp('data');
在文档中找到

.withDataProp设置