带有bootstrap-table的未捕获的TypeError和带有服务器端分页的角度

时间:2015-10-30 14:59:30

标签: angularjs bootstrap-table

我得到了Uncaught TypeError: bsTable.$s.$applyAsync is not a function。 HTML页面代码:

<div ng-app="testapp">
  <div ng-controller="MainController">
    <table bs-table-control="dashboardTableControl"></table>
  </div>
</div>

Javascript部分:

<script type="text/javascript">
  angular.module('testapp', ['bsTable'])
    .controller('MainController', function($scope, $http) {
      $scope.dashboardTableControl = {
        options: {
          url: "/tasks/",
          cache: false,
          height: 400,
          striped: true,
          pagination: true,
          pageSize: 10,
          pageList: [5, 10, 25, 50, 100, 200],
          search: true,
          showColumns: true,
          showRefresh: false,
          minimumCountColumns: 2,
          clickToSelect: false,
          showToggle: true,
          maintainSelected: true,
          sortName: "date_done",
          sidePagination: "server",
          columns: [{
            field: 'status',
            title: 'Status',
            sortable: true,
            editable: true,
            align: 'center'
          }, {
            field: '_id',
            title: 'Task ID',
            sortable: true,
            editable: true,
            align: 'center'
          }, {
            field: 'date_done',
            title: 'Date Completed',
            sortable: true,
            editable: true,
            align: 'center'
          }]
        }
      };
    });
</script>

我已将依赖项导入为:

<script type="text/javascript" src="/static/bower_components/bootstrap-table/src/bootstrap-table.js"></script>
<script type="text/javascript" src="/static/bower_components/bootstrap-table/dist/extensions/angular/bootstrap-table-angular.js"></script>

和我的bower.json:

"bootstrap-table": "1.9.0",
"angular": "~1.2.28",
"angular-route": "~1.2.28",
"angular-resource": "~1.2.28",

任务api也会将结果返回为:

{"rows": [{"status": "SUCCESS", "_id": "db672f91-cf56-4cf1-add2-216e7b069bbb", "date_done": "March 22, 2015 07:17:19 AM"}, {"status": "SUCCESS", "_id": "a44b670c-83c4-49ad-bbe4-11403c1b736e", "date_done": "March 22, 2015 07:17:29 AM"}, {"status": "SUCCESS", "_id": "ac60726e-edf7-4222-9cbb-88cfed5be69b", "date_done": "March 22, 2015 07:17:29 AM"}, {"status": "SUCCESS", "_id": "d3668982-bb3f-42b5-82eb-9b09ead36766", "date_done": "March 22, 2015 07:17:31 AM"}, {"status": "SUCCESS", "_id": "f97f89c1-53ff-4959-a2ad-2e7cfad37f48", "date_done": "March 22, 2015 07:17:41 AM"}, {"status": "SUCCESS", "_id": "84048949-ded1-4fe9-b699-d904c69d9d6c", "date_done": "March 22, 2015 07:17:42 AM"}, {"status": "SUCCESS", "_id": "3e06d66b-ba64-4d27-af8d-852356cd0063", "date_done": "March 22, 2015 07:17:44 AM"}, {"status": "SUCCESS", "_id": "82546768-461c-4474-9acb-0954e161e83c", "date_done": "March 22, 2015 07:17:52 AM"}, {"status": "SUCCESS", "_id": "92109e36-d27d-474a-a3e2-f34b743e3fbc", "date_done": "March 22, 2015 07:17:54 AM"}, {"status": "SUCCESS", "_id": "c4d6c39b-facc-4a88-8aa6-15753d7297ab", "date_done": "March 22, 2015 07:17:54 AM"}], "total": 109}

我犯了错误?

1 个答案:

答案 0 :(得分:1)

我得到了同样的错误,我通过以下更改解决了

打开bootstrap-table-angular.js文件,将$applyAsync替换为$evalAsync

它解决了错误,因为这是Angular ^ 1.4中的首选方法。