とAngularJS(およびバックエンドのMySQL)をプロジェクトに使用しています。私はMySQLデータベースからそのデータを取得するテーブルを得ました。その行(またはセル)は編集可能です(ui-grid Webサイトのexampleに記載されています)。テーブルの1列にドロップダウンがあります。ドロップダウンは、この例で説明したように、ハードコードされたデータで完全に動作しています。私はデータベースからそれを設定したいのですが、私が試したたびに空のドロップダウンリストが表示されます。ダイナミックデータをuiグリッドドロップダウンに読み込むことができません
データベースからデータを取得することは、データベースにデータを取得するコード(つまり$ http.get( '/ some/route'))を実行する意図でコントローラに注入されるサービスによって行われます。ページローディングの前またはページローディング時のテーブル行およびドロップダウンリストのデータ。
しかし、印刷時にドロップダウンのデータを取得する変数(sitesD)は、未定義であることを示しています。サービスの
angular.module('WorkersCtrl', []).controller('WorkersController', function($scope, $http, serverData) {
$scope.gridOptions = {enableHorizontalScrollbar: 1};
/* getting rows from databse by using "serverData" custom service */
serverData.getData().then(function(response) {
$scope.gridOptions.data = response.data[0];
$scope.sitesData = response.data[1];
});
var sitesD = $scope.sitesData;
$scope.gridOptions.columnDefs = [
{ field: 'first_name', width:150, enableCellEdit: true},
{ field: 'last_name', width:150},
{ field: 'father_first_name', width:150},
{ field: 'father_last_name', width:150},
{ field: 'mother_first_name', width:150},
{ field: 'mother_last_name', width:150},
{ field: 'sex', width:50, editableCellTemplate: 'ui-grid/dropdownEditor',
editDropdownValueLabel: 'gender', editDropdownOptionsArray: [
{ id: 'M', gender: 'Male' },
{ id: 'F', gender: 'Female' }]},
{ field: 'address', width:250},
{ field: 'phone', width:100, type: 'number'},
{ field: 'date_of_birth', width:150, type: 'date', cellFilter: 'date:"yyyy-MM-dd"'},
{ field: 'post_code', displayName: 'Post', width:50},
{ field: 'joining_date', width:150, type: 'date', cellFilter: 'date:"yyyy-MM-dd"'},
{ field: 'rate', width:50, type: 'number'},
{ field: 'site_name', width:150, editableCellTemplate: 'ui-grid/dropdownEditor',
editDropdownIdLabel:'site_id', editDropdownValueLabel: 'site_name', editDropdownOptionsArray: sitesD },
];
alert(sitesD); //checking the variable value: it shows undefined.
$scope.gridOptions.onRegisterApi = function(gridApi){
$scope.gridApi = gridApi;
};
$scope.addData = function() {
$scope.gridOptions.data.push({
'first_name': '',
'last_name': '',
'father_first_name': '',
'father_last_name': '',
'mother_first_name': '',
'mother_last_name': '',
'sex': '',
'address': '',
'phone': '',
'date_of_birth': '',
'post_code': '',
'joining_date': '',
'rate': '',
'site_name': ''
});
};
});
私は理解してどのような変数である:ここでは
angular.module('GeekService', []).factory('serverData', ['$http', function($http) {
return {
getData: function() {
return $http.get('/workers')
}
}
}]);
はalert(sitesD);
実行がページのスクリーンショットです。ここ
コントローラがありますページが読み込まれた後に値を取得するので、editDropdownOptionsArray
はドロップダウンの値を取得しません。
これらはすべて私が解決策を探している間に作成したものですが、まだ終了していません。私を助けてください。私は問題がどこにあるのか分からないと感じています。
必要に応じて詳しい情報をお気軽にお尋ねください。
PS:質問を書いているうちに、私の角とuiグリッドの間にバージョンの非互換性があります。 ui-grid 3.xはAngularの1.4.xと互換性がありますが、私はui-grid 3.xをAngular 1.5.5で使用しています。理由はありますか?
編集:ここでは、ドロップダウンがどのように見えるかを示す、スクリーンショットです:
にこれを追加; ' –
私は、次のようにそれを試してみました: ' serverData。 getData()。次に(function(response){ $ scope(){ $ scope.gridOptions.data = response.data [0]; $ scope.sitesData = response.data [1]; }); }); ' エラー:$ rootScope:inprog アクションは既に進行中です – harman052