0

我有一个对数据库进行 HTTP 调用的控制器。它返回由 $log 命令验证的数据,但不在网格中显示。这是代码..

提前致谢...

eventsApp.controller('TerrController',    
function TerrController($scope, territoryData) {
    $scope.territory = [];

    //$scope.gridOptions = {
    //    data: 'territory', columnDefs: [
    //        { field: 'TerritoryID', displayName: 'ID'},
    //        { field: 'TerritoryDescription', displayName: 'Description' },
    //        { field: 'RegionID', displayName: 'RegionID' }]
    //};

    territoryData.getTerritories().then(function (response) {
        var tmpData = angular.fromJson(response);
        $scope.territory = tmpData;
    });
    $scope.gridOptions = {
        data: 'territory', columnDefs: [
            { field: 'RegionID', displayName: 'RegionID', visible: true },
            { field: 'TerritoryDescription', displayName: 'Description', visible: true     },
            { field: 'TerritoryID', displayName: 'ID', visible: true }]
    };

});

eventsApp.factory('territoryData', function ($http, $q, $log) {
return {
    getTerritories: function () {

        var deferred = $q.defer();

        $http({ method: 'GET', url: '/Home/GetTerritories' }).
        success(function (result, status, headers, config) {
            angular.forEach(result, function (c) {
                $log.log(c.TerritoryDescription);
            });

            deferred.resolve(result);

        }).
        error(function (result, status, headers, config) {
            deferred.reject(status)
        });
        return deferred.promise;
    }
}

});


4

0 回答 0