角度ui-grid不更新

时间:2015-10-11 08:29:23

标签: javascript angularjs angular-ui-grid

我有一个带有文本框,按钮和ui网格的Angular模板,用于显示添加的项目:



<form name="frmNewPlace" ng-submit="newPlace()">
  <div class="sectionTitle">Add a new place</div>
  <div class="contentSection">
    <input type="text" name="placeName" ng-model="dataStoreNewPlace.Name">
    <input type="submit" value="Add place" />
  </div>
</form>

<div class="sectionTitle">Existing places</div>
<div class="contentSection">
  <div id="placesGrid" class="grid" ui-grid="gridOptions"></div>
</div>
&#13;
&#13;
&#13;

控制器:

function getPlaces($scope, $http){
  $scope.gridOptions = {
    enableFiltering: true,
    columnDefs: [
    {field: 'name', displayName: 'Place Name'}]}

  $http({method: 'GET', url: 'api/GetPlaces'}).then(function (response) {
  $scope.gridOptions.data = response.data;
  }, function(response){
    console.log('failed:' + response);
  });
}

scannfeast.controller('placesController', ['$scope', '$http', function($scope, $http){
  getPlaces($scope, $http);

  $scope.dataStoreNewPlace = {};
  $scope.newPlace = function(){
  $http.post('/api/NewPlace',   $scope.dataStoreNewPlace).success(function(data){
  getPlaces($scope, $http);});
}

}]);

我添加新项目后可以看到GET请求,但是ui-grid不会自行更新。刷新页面时,新项目符合预期。

我尝试使用下面的代码强制ui-grid更新,但它似乎没有任何效果:

$scope.gridApi.core.queueGridRefresh();
$scope.gridApi.core.refresh();
$scope.gridApi.grid.refreshCanvas();
$scope.gridApi.grid.refreshRows();

我还尝试使用$apply()强制更新ng-view,但我收到一条错误消息,说明摘要已经到位。

有什么想法吗?

0 个答案:

没有答案