2015-04-23 104 views
3

我已經實現了一個ajax調用的ng表,但從來沒有從getdata調用函數,函數onBuscarTable是從來沒有調用,我看debbugger控制檯來檢查它,並dosen不叫它:Ng表沒有調用獲取數據

我在做什麼?

這裏的JS:

$scope.onBuscarTable = function ($defer, params) { 
    $.ajax({ 
     type: 'GET', 
     url: '/Home/GetEfficiencyDetails', 
     cache: false, 
     contentType: 'application/json; charset=utf-8', 
     //data: JSON.stringify({ title: "fghfdhgfdgfd" }), 
     success: function (data) { 
      $scope.items = data; 
      $defer.resolve(data); 
     } 
    }); 
}; 

//$scope.getEffiencyDetails(); 
$scope.tableBuscar = new ngTableParams({ 
    page: 1, // show first page 
    count: $scope.items.length, // hides pager 
    sorting: { 
     name: 'asc' // initial sorting 
    } 
}, { 
    counts: [], // hides page sizes 
    getData: $scope.onBuscarTable 

}); 

$scope.tableBuscar.reload(); 

這裏是HTML:爲什麼要使用$就不是

      <table ng-table="tableBuscar" show-filter="true" class="table table-striped table-bordered table-condensed table-hover"> 

          <tbody> 
           <tr> 
            <th colspan="5">Battery Life</th> 
            <th colspan="4">SBC</th> 
            <th colspan="3">ZBC</th> 
            <th>Overall</th> 
           </tr> 
           <tr> 
            <th>Pool #</th> 
            <th>True Cap.</th> 
            <th>Util.</th> 
            <th>Load Sharing</th> 

           </tr> 
           <tr ng-repeat="item in items"> 
            <td>{{item.PoolName}}</td> 
            <td>{{item.AvgTrueCapacity}}</td> 
            <td>{{item.AvgEnergyUsageDaily}}</td> 
           </tr>         

          </tbody> 
         </table> 
+1

的$ http服務從angularjs –

+0

我在另一個項目中使用它,它wor ks –

+0

我寧願你使用$ http服務,而不是$ .ajax,你也不應該混合使用jQuery和angularjs –

回答

0

您的代碼應該使用$http代替$.ajax

$scope.items = []; 
$scope.onBuscarTable = function($defer, params) { 
    $http.get('/Home/GetEfficiencyDetails').success(function(data) { 
     $scope.items = data; 
     $defer.resolve(data); 
    }); 
}; 

//$scope.getEffiencyDetails(); 
$scope.tableBuscar = new ngTableParams({ 
    page: 1, // show first page 
    count: $scope.items.length, // hides pager 
    sorting: { 
     name: 'asc' // initial sorting 
    } 
}, { 
    counts: [], // hides page sizes 
    getData: $scope.onBuscarTable 

}); 

$scope.tableBuscar.reload(); 
+0

它可以工作,但它是三次調用,爲什麼會這樣呢? GET http:// localhost:4684/Home/GetEfficiencyDetails 200 OK GET http:// localhost:4684/Home/GetEfficiencyDetails 200 OK GET http:// localhost:4684/Home/GetEfficiencyDetails 200 OK –

+0

因爲在裏面使用jquery角度不會運行角度摘要,你需要手動更新它.. –

+1

@DiegoUnanue它的調用多次,因爲'$ scope.tableBuscar.reload();'這一行 –