weixin_33724659 2017-01-06 18:07 采纳率: 0%
浏览 35

为什么Ajax调用填充$作用域事务不显示任何内容?

我使用Bootstrap的分页指令将分页添加到表中。奇怪的是,当我手动添加到$作用域事务时分页运行非常好,但是,当我试图通过Ajax调用填充$作用域事务时,该表没有显示任何内容。Ajax调用返回以下内容:

[{"date":"2017-01-06","amount":123,"action":"Deposit","id":1},{"date":"2017-01-06","amount":200,"action":"Deposit","id":2},{"date":"2017-01-06","amount":400,"action":"Deposit","id":3}]

视图:

    <tr ng-repeat="transaction in f ">

    <td>{{transaction.id}}</td>
    <td>$ {{transaction.amount}}</td>
    <td>{{transaction.action}}</td>
    <td>{{transaction.date}}</td>
    </tr>
    </table>
    <pagination 
          ng-model="currentPage"
          total-items="transactions.length"
          max-size="maxSize"  
          boundary-links="true">
        </pagination>  

Controller:

 var mmyApp = angular.module('myApp',['ui.bootstrap']).controller('TasksController',  TasksController);
     function TasksController($scope, $http) {

     $scope.f = []
      ,$scope.currentPage = 1
      ,$scope.numPerPage = 3
      ,$scope.maxSize = 5;
     $scope.transactions = [];
    $scope.history = "";

    $http.get('transactions').then(function (response) {

         $scope.transactions = response.data;
     }, function (error) {
         throw error;
     });

     //if i use this commented out code instead of the AJAX call, the pagination works fine
     /*$scope.makeTransactions = function() {
            $scope.transactions = [];
            for (i=1;i<=1000;i++) {
              $scope.transactions.push({"id":i});
            }
          };
          $scope.makeTransactions();
          */
     $scope.$watch('currentPage + numPerPage', function() {
            var begin = (($scope.currentPage - 1) * $scope.numPerPage)
            , end = begin + $scope.numPerPage;

            $scope.f = $scope.transactions.slice(begin, end);
          });


 }
  • 写回答

1条回答 默认 最新

  • weixin_33716557 2017-01-06 18:14
    关注

    You forgot to populate $scope.fafter populating $scope.transactions in your ajax call. In your ng-repeat you're cycling through items that should be stored in $scope.f but it's empty.

    评论

报告相同问题?

悬赏问题

  • ¥15 求差集那个函数有问题,有无佬可以解决
  • ¥15 MATLAB动图问题
  • ¥15 【提问】基于Invest的水源涵养
  • ¥20 微信网友居然可以通过vx号找到我绑的手机号
  • ¥15 寻一个支付宝扫码远程授权登录的软件助手app
  • ¥15 解riccati方程组
  • ¥15 display:none;样式在嵌套结构中的已设置了display样式的元素上不起作用?
  • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名