JSON数据不以角度显示在ng-grid中

时间:2013-09-30 01:47:18

标签: asp.net angularjs ng-grid

我有一个控制器对数据库进行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;
    }
}

});

                                
                         

0 个答案:

没有答案