2016-06-09 60 views
0

我有剑道网格,由角控制器控制:如何显示在剑道格列相关的外键数据

<div> 
    <kendo-grid options="mainGridOptions" k-data-source="gridData"> 
    </kendo-grid> 
</div> 

UPDATE 的数据加载,但网格ISN” t呈现。 (我也有一个期限错配和处理领域的地位。

"use strict"; 
angular.module("tenderApp") 
.controller("tenderCtrl", ["$scope", "adalAuthenticationService", "tenderSvc", "$q", function ($scope, adalService, tenderSvc, $q) { 
    $scope.mainGridOptions = null; 
    $scope.gridSource = null; 
    $scope.statusData = null; 

    function loadStatusData() { 
     return tenderSvc.getSector() 
      .then(function(sector) { 
       $scope.sectorData = sector.data.map(function (obj) { 
        return { 
         text: obj.bezeichnung, 
         value: obj.id 
        }; 
       }); 
       return $scope.sectorData; 
      }); 
    } 

    function loadGridSource(result) { 
     return tenderSvc.getItems() 
      .then(function (res) { 
       $scope.gridSource = res.data; 
       return res.data; 
      }); 
    } 

    loadStatusData() 
     .then(loadGridSource) 
     .then(function (res) { 
      //both properties are available at this point 
      console.log($scope.gridSource); 
      console.log($scope.sectorData); 
      $scope.gridData = new kendo.data.DataSource({ 
       transport: { 
        read: function (e) { 
         e.success($scope.gridSource); 
        }, 
        //... 
       }, 
       //... 
      }); 
      $scope.mainGridOptions = { 
       toolbar: ["excel"], 
       dataSource: $scope.gridData, 
       columns: [ 
        { field: "sektor", title: "Sektor", values: $scope.sectorData }, 
        { command: ["edit"], title: "Aktionen", width: "120px" } 
       ] 
      }; 

     }); 
}]); 

的问题是,在最后一次通话,这应该填充网格,不能正常工作。该console.log来电显示,数据加载,但网格不显示

回答

1

不错的一个,现在我学会了如何做你的链接,至于你的问题,我们不需要使用transport/read,而是我们可以单独加载数据并设置它到这个网格dataSource请注意,请不要把k-data-source="gridData"放在你的网格html属性中,因为你已经有了网格选项

HTML:

<div><kendo-grid options="mainGridOptions" k-data-source="gridData"> 
    </kendo-grid></div> 

JS:

"use strict"; 
angular.module("tenderApp") 
.controller("tenderCtrl", ["$scope", "adalAuthenticationService", "tenderSvc", "$q", function ($scope, adalService, tenderSvc, $q) { 
    $scope.mainGridOptions = null; 
    $scope.gridSource = null; 
    $scope.statusData = null; 

    $scope.mainGridOptions = { 
     dataSource: new kendo.data.DataSource(), 
     toolbar: ["excel"], 
     columns: [ 
      { field: "sektor", title: "Sektor", values: $scope.sectorData }, 
      { command: ["edit"], title: "Aktionen", width: "120px" } 
     ] 
    }; 

    function loadStatusData() { 
     return tenderSvc.getSector() 
      .then(function(sector) { 
       $scope.sectorData = sector.data.map(function (obj) { 
        return { 
         text: obj.bezeichnung, 
         value: obj.id 
        }; 
       }); 
       return $scope.sectorData; 
      }); 
    } 

    function loadGridSource(result) { 
     return tenderSvc.getItems() 
      .then(function (res) { 
       $scope.gridSource = res.data; 
       return res.data; 
      }); 
    } 

    loadStatusData() 
     .then(loadGridSource) 
     .then(function (res) { 
      $scope.mainGridOptions.dataSource.data($scope.gridSource); 
     }); 
}]); 
+0

您的文章帮助我明白了,什么地方出了问题检索数据。我的工厂已经退货了。我会很快更新我的问题,因为承诺问题似乎已经解决,但网格仍然无法加载。 – Marco