2017-07-03 170 views
0

当我将数据加载到UI格,我有这样的错误colDef.name or colDef.field property is requiredUI格列definiton错误

我没有在互联网上找到一个解决方案来解决这个问题。

这是我的功能,填补了网格:因为你是使用jQuery AJAX发送HTTP请求

$scope.ApiGet = function() { 
    $.ajax({ 
     url: //an url, 
     async: false, 
     type: 'POST', 
     dataType: 'json',    
     success: function (data, textStatus, xhr) { 
      var token = data.access_token; 
      console.log(token); 
      $.ajax({ 
       url: //an other url 
       async: false, 
       crossDomain: true, 
       type: "GET", 
       datatype: "json",      
       success: function (datas, textStatus, request) { 
        console.log(datas[0].previewContent);       
        angular.forEach(datas, function (value) { 
         console.log(value); 
         debugger; 
         if (value) { 
          $scope.rowCollection = $scope.rowCollection.concat(value.previewContent); 
         } 

        }) 
        // console.log($scope.rowCollection); 
       }, 
       error: function (jqXHR, textStatus, errorThrown) { 

        // $scope.addAlert(jqXHR.responseText != "" ? jqXHR.responseText : jqXHR.statusText); 
       } 
      }) 

和HTML

<div ng-controller="listCtrl" ng-init="ApiGet()"> 
    <div ui-grid="{ data: rowCollection }" class="myGrid"></div> 
</div> 

回答

0

,棱角分明的消化周期可能已停止。所以即使您分配了$scope.rowCollection值,它也不会绑定到html。

一两件事你可以做的是使用$scope.$apply() HTTP响应后

success: function(datas, textStatus, request) { 
    console.log(datas[0].previewContent); 
    angular.forEach(datas, function(value) { 
     console.log(value); 
     debugger; 
     if (value) { 
      $scope.rowCollection = $scope.rowCollection.concat(value.previewContent); 
     } 

    }) 
    $scope.$apply(); 
}, 

OR

可以使用$http而不是$.ajax发送HTTP开始消化周期请求

+0

我的要求是异步=假,所以当我加入$范围$适用(),它说我$文摘已在进行中,所以我把请求异步=。真的,那么我有同样的错误。我试图用colum定义创建gridOption,但仍然是相同的 –

0

我已经找到解决办法:

定义了一个

$scope.gridOptions {data:mydata, 
        columnDefs:[{field:'field1',displayName:'Field1", width:"*"}, 
           {field:'field2',displayName:'Field2", width:"*"}] 

然后在HTML:

<div ng-controller="listCtrl" ng-init="ApiGet()"> 
    <div ui-grid="gridOptions" class="myGrid"></div> 
</div>