2015-10-20 76 views
0

我想传递数据值ui-grid.I需要将$ scope.ll值传递给ui-grid.If我复制数据并分配$ scope.ll = [{} Id和stateum_totalcount运行良好。我需要传递$ scope.ll电网将数据值传递给ui-grid

我的数据阵列作为

{ 
"ID": "3", 
"stat_sum": { 
    "totcount": 3 
}, 
"zip_stats": [ 
    { 
     "zip": "560045", 
     "count": 1 
    }, 
    { 
     "zip": "567657", 
     "count": 2 
    } 
], 
"qual_stats": [ 
    { 
     "count": 1, 
     "qualification": "B.E." 
    }, 
    { 
     "count": 2, 
     "qualification": "BE" 
    } 
], 
"prof_stats": [ 
    { 
     "count": 1, 
     "profession": "Doctor" 
    }, 
    { 
     "count": 2, 
     "profession": "Software Engineer" 
    } 
], 
"city_stats": [ 
    { 
     "city": null, 
     "count": 2 
    }, 
    { 
     "city": "Bangalore", 
     "count": 1 
    } 
], 
"state_stats": [ 
    { 
     "count": 1, 
     "state": "Karnataka" 
    }, 
    { 
     "count": 2, 
     "state": "Kerala" 
    } 
], 
"stats_info": [ 
    { 
     "acount": 3, 
     "answer": "fgdfgd", 
     "question": "comment-about-me-" 
    }, 
    { 
     "acount": 1, 
     "answer": "one", 
     "question": "radio-answer-" 
    }, 
    { 
     "acount": 2, 
     "answer": "two", 
     "question": "radio-answer-" 
    }, 
    { 
     "acount": 3, 
     "answer": "t-shirt", 
     "question": "select-any-dress-for-me-[]" 
    }, 
    { 
     "acount": 3, 
     "answer": "no", 
     "question": "say-yes-or-no-" 
    }, 
    { 
     "acount": 3, 
     "answer": "2015-09-25", 
     "question": "select-your-b.date-" 
    }, 
    { 
     "acount": 3, 
     "answer": "24", 
     "question": "select-your-age-" 
    }, 
    { 
     "acount": 3, 
     "answer": "2", 
     "question": "type-number-" 
    }, 
    { 
     "acount": 3, 
     "answer": "false", 
     "question": "select-true-or-false-" 
    } 
] 
} 

在控制器

$timeout(function() { 
    console.log($scope.ll); //works fine 
     $rootScope.showspinner = false; 
     $scope.gridOptionsComplex = { 
      enableFiltering: true, 
      showGridFooter: true, 
      showColumnFooter: true, 
      columnDefs: [ 

       {name: 'ID', width: 100, enableCellEdit: false,}, 
       {name: 'stat_sum.totcount', width: 100, enableCellEdit: false,}, 
       {name: 'zip_stats.zip', width: 100, enableCellEdit: false,}, 
       {name: 'zip_stats.count', width: 100, enableCellEdit: false,}, 
       {name: 'qual_stats.qualification', width: 100, enableCellEdit: false,}, 
       {name: 'qual_stats.count', width: 100, enableCellEdit: false,}, 
      ], 

    data:$scope.ll 
     }; 
     $scope.$apply(function() { 
      $scope.aut = true; 
     }); 
    }, 500, false); 

回答

0

同类的我面临的问题,我给一个例子代码如何解决这个问题

{ 
"result": { 
    "fileNames": [ 
     "Book1 (2).csv", 
     "address_sample (3).csv", 
     "Book1.csv" 
    ], 
    "ids": [ 
     1, 
     2, 
     3 
    ] 
}, 
"responseSuccess": "success", 
"responseError": null, 
"responseInfo": null, 
"responseWarning": null, 
"responseCode": 0 
} 

我有像上述格式的输出,我也必须与这些集成到ui-网格。

例如控制器端代码一旦控制达到成功的一部分我收到输出的上述格式,所以让我们看看如何使用UI电网整合,

在我的控制器我有$scope.gridsOptions喜欢

$scope.gridsOptions = { 
columnDefs : [ 
    { 
     field : 'field', 
     name : 'Id' 
    }, 
    { 
     field : 'filename', 
     name : 'FileName' 
    }] 
} 

我认为控制来什么都验证请你确认,然后成功部分.success(function())

.success(function(data){ 
$scope.resultValues =[]; 

// Here My PD(Problem Domain says iterate based On `ids`) 
for (var i = 0; i < data.result.ids.length; i++) { 

     // Im getting each ID in $scope.fileId variable 
     $scope.fileId = data.result.ids[i]; 

     // Here Im getting each fieldNames in $scope.fileName variable 
     $scope.fileName = data.result.fileNames[i]; 

     //Then I am pushing those values in to fieldId 
     $scope.resultValues.push({ 
         field : $scope.fileId, 
         filename : $scope.fileName 
       }); 
     } 

     ListData.fileIdValues = angular.copy($scope.resultValues); 

     // I am pointed those to $scope.gridsOptions.data 
     $scope.gridsOptions.data = ListData.fileIdValues; 
})               

请注意ListData.fileIdValues在我的代码是角服务变量this.fileIdValues ={}。对于我的问题域,我需要这些值,因此我将它存储在service中,并在任何需要的地方使用它。

+0

你能解释一下先生吗? – user3386779

+0

你能告诉我哪个部分? – SakthiSureshAnand

+0

我怎么能modidy columnDefs:[]我的数组值的先生以及如何使用data.result.ids.length – user3386779