2015-10-20 119 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