如何访问行选择上的行数据

时间:2015-03-19 21:45:27

标签: angularjs angular-ui-grid

我使用ui-grid来显示数据。

我想在选择行时访问列的值。我已经实施了rowSelectionChange活动,但我似乎无法访问这些数据。

gridOptions

$scope.gridOptions = {
paginationPageSizes: [10, 25, 50],
paginationPageSize: 25,   
useExternalPagination: true,
useExternalSorting: true,
multiSelect: false,
enableSelectAll: false,
columnDefs: [
  { name: 'Name', field: 'properties.Name'},
  { name: 'Address', field: 'properties.Address'},
  { name: 'PhoneNumber', field: 'properties.PhoneNumber'}
],

onRegisterApi: function(gridApi) {
    $scope.gridApi = gridApi;
    $scope.mySelectedRows = $scope.gridApi.selection.getSelectedRows();
    gridApi.selection.on.rowSelectionChanged($scope, function(row) {
        var msg = row.entity.Name;
        alert("Row Selected! " + msg);
    });
...

我错过了什么?

2 个答案:

答案 0 :(得分:2)

通过添加断点并查看row.entity的值来找到解决方案。将其更改为row.entity.properties.Name解决了我的问题。

答案 1 :(得分:1)

你应该使用row.entity.name而不是row.entity。 N ame

$scope.gridOptions = {
paginationPageSizes: [10, 25, 50],
paginationPageSize: 25,   
useExternalPagination: true,
useExternalSorting: true,
multiSelect: false,
enableSelectAll: false,
columnDefs: [
  { name: 'Name', field: 'properties.Name'},
  { name: 'Address', field: 'properties.Address'},
  { name: 'PhoneNumber', field: 'properties.PhoneNumber'}
],

onRegisterApi: function(gridApi) {
    $scope.gridApi = gridApi;
    $scope.mySelectedRows = $scope.gridApi.selection.getSelectedRows();
    gridApi.selection.on.rowSelectionChanged($scope, function(row) {
        var msg = row.entity.name; //change Name -> name.
        alert("Row Selected! " + msg);
    });
...