Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/21.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript ui网格列定义错误_Javascript_Angularjs_Angular Ui Grid - Fatal编程技术网

Javascript ui网格列定义错误

Javascript ui网格列定义错误,javascript,angularjs,angular-ui-grid,Javascript,Angularjs,Angular Ui Grid,当我将数据加载到Ui网格时,出现此错误colDef.name或colDef.field属性是必需的 我在互联网上没有找到解决这个问题的方法 这是我填写表格的功能: $scope.ApiGet = function () { $.ajax({ url: //an url, async: false, type: 'POST', dataType: 'json', success: fu

当我将数据加载到Ui网格时,出现此错误
colDef.name或colDef.field属性是必需的

我在互联网上没有找到解决这个问题的方法

这是我填写表格的功能:

 $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>

因为您使用jquery AJAX发送http请求,所以角度摘要周期可能会停止。因此,即使您分配了
$scope.rowCollection
值,它也不会绑定到html

您可以做的一件事是在http响应之后使用
$scope.$apply()
启动摘要循环

 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();
 },


您可以使用
$http
而不是
$。ajax
发送http请求

我找到了解决方案:

定义一个

$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>

我的请求是async=false,所以当我添加$scope.$apply()时,它说我的$Digest已经在进行中,所以我将请求设置为async=true,然后我出现了相同的错误。我试图用colum定义创建gridOption,但仍然是相同的eroor