【问题标题】:Calling function synchronizely in angularjs在angularjs中同步调用函数
【发布时间】:2016-01-16 10:14:56
【问题描述】:

我正在使用透视网格来显示数据库中的数据,所以我通过 ajax 获取数据,同步中的问题,在从数据库中获取数据之前加载了透视网格

如何在执行透视网格之前检索数据?

函数 getData() 从数据库中检索数据

   function getData{
    ScoreService.getAverageScore($stateParams.id).then(function(output){
         $scope.jsonData=output; 
    });
    }

枢轴网格代码

     $scope.pivotData = new $.ig.OlapFlatDataSource({
        dataSource:$scope.jsonData,
        metadata: {
            cube: {
                name: "Sales",
                caption: "Route Scores",
                measuresDimension: {
                    caption: "Measures",
                    measures: [ //for each measure, name and aggregator are required
                        {
                            caption: "Score Value", name: "Value",
                            // returns a function that will be used as sum aggregator on the 'UnitsSold property' of the data objects
                            aggregator: $.ig.OlapUtilities.prototype.sumAggregator('Value')
                        }]
                },
                dimensions: [ // for each dimension name and hierarchies are required
                    {
                        caption: "Rules", name: "ScoreCategory", hierarchies: [{
                            caption: "Score Category", name: "ScoreCategory", levels: [
                                {
                                    name: "AllCategories", caption: "All Categories",
                                    memberProvider: function (item) { return "All Categories"; }
                                },
                                {
                                    name: "CategoryName", caption: "Category",
                                    memberProvider: function (item) { return item.ScoreCategoryName; }
                                }]
                        }]
                    },
                    {
                     caption: "Scenarios", name: "Scenario", hierarchies: [{
                            caption: "Scenario Category", name: "Scenario", levels: [
                                {
                                    name: "AllScenarios", caption: "All Scenarios",
                                    memberProvider: function (item) { return "All Scenarios"; }
                                },
                                {
                                    name: "ScenarioName", caption: "Scenario",
                                    memberProvider: function (item) { return item.ScenarioName; }
                                }]
                        }]
                    }
                ]
            }
        },
        // Preload hierarchies for the rows, columns, filters and measures
        rows: "[Scenario].[Scenario]",
        columns: "[ScoreCategory].[ScoreCategory]",
        measures: "[Measures].[Value]"
    });
    });

【问题讨论】:

    标签: angularjs ajax pivot-table angular-resource


    【解决方案1】:

    您可以同步 AJAX 调用的结果以实例化您的网格:

    $scope.$watch(function() {return $scope.jsonData}, function(oldV, newV) {
        if ((newV) && (newV != oldV)) {
            $scope.pivotData = new $.ig.OlapFlatDataSource({
            dataSource:$scope.jsonData,
    
            // your function
            ...
        }
    }
    

    【讨论】:

    • 数据透视表不显示
    • 如果您在if ((newV) && (newV != oldV)) { 和if ((newV) && (newV != oldV)) { 上设置断点,它们会被调用吗?
    猜你喜欢
    • 2014-01-03
    • 2012-07-25
    • 2020-12-20
    • 2014-02-05
    • 2015-03-01
    • 1970-01-01
    • 2013-07-12
    • 2015-03-19
    • 2020-04-20
    相关资源
    最近更新 更多