0

Demo link在AngularJS中選擇多列無法正常工作?

大家好,

我創建了一個樣本選擇與AngularJS多列。如果我直接傳遞值這樣這是工作的罰款:

$scope.rowDatas = [ 
        { ID: "09-14-002880", PatientName: "PRAVEEN KUMAR", Gender: "Male", Age: "20", mobileNumber: 9879878971, patientId: "test" }, 
        { ID: "09-13-000188", PatientName: "VAR", Gender: "Male", Age: "20", mobileNumber: '', patientId: "ZXC12" }, 
        { ID: "09-05-019825", PatientName: "KARMA", Gender: "Male", Age: "29", mobileNumber: '', patientId: "ZA2545635" }, 
        { ID: "09-04-010524", PatientName: "FRANKLIN ANTHONY", Gender: "Male", Age: "20", mobileNumber: '', patientId: "Z7552396" }, 
        { ID: "09-08-009303", PatientName: "DARYOUSH", Gender: "Male", Age: "29", mobileNumber: '', patientId: "Z2548467" }, 
        { ID: "09-12-031048", PatientName: "SMITA", Gender: "Female", Age: "20", mobileNumber: 9880222187, patientId: "Z2296538" }, 
        { ID: "09-11-026001", PatientName: "ADITYA DILIP", Gender: "Male", Age: "29", mobileNumber: '', patientId: "Z2277913" } 
    ]; 

但我究竟需要的是我需要從廠家獲得的價值

dtfactory.getdata().then(function(response){ 
    //$scope.rowDatas = response.data; 
}) 

這裏response.data也含有相同的數據。如果我評論直接代碼和取消註釋工廠代碼它不工作可能我知道我的錯誤在哪裏?任何人都可以幫助我。

+0

確保你的工廠函數'dtfactory.getdata()'應該返回promise。或者你也可以分享你的工廠代碼。 – Vineet

回答

0

嘗試在你的控制器做這樣

$scope.rowDatas = dtfactory.getdata().then(function(response){ 
    $scope.rowDatas = response.data; 
}) 
0

試試下面的代碼:

首先獲取JSON數據並調用displayTable功能:

dtfactory.getdata().then(function(response){ 
     $scope.rowDatas = response.data; 
     dispalyTable(); 
    }) 

    function dispalyTable(){ 
     $scope.gridOptions = { 
        columnDefs: $scope.gridheaders, 
        rowData: $scope.rowDatas, 
       }; 

     //document.addEventListener('DOMContentLoaded', function() { 
      var gridDiv = document.querySelector('#myGrid_'+textBoxId); 
      new agGrid.Grid(gridDiv, $scope.gridOptions); 
     //}); 
    } 
+0

@哈利感謝您的回覆,我更改了您的代碼,但無法正常工作 – Nelson

+0

您能否告訴我哪些工作不正常? $ scope.rowDatas沒有更新嗎? – harry

+0

是的Harry,$ scope.rowDatas沒有更新。 – Nelson

相關問題