ui-grid 3.0.0 中的 selectedItem

selectedItem in ui-grid 3.0.0

我目前正在测试 angular ui-grid 3.0.0。按照旧版本的示例代码,selectedItems 在被选中时应该包含一些对象。在版本 3 中,它似乎不起作用。有人遇到过同样的行为吗?

Angularjs版本:1.3.11 Angular-ui-网格:3.0.0-rc.16 这是我的控制器中的一些提取代码:

$scope.gridOptions = {  };
$scope.mySelections = [];

$scope.gridOptions = {
    enableRowSelection: true,
    enableRowHeaderSelection: false,
    modifierKeysToMultiSelect: true,
    multiSelect: true,
    pagingPageSize: 25,
    useExternalPagination: true,
    useExternalSorting: true,
    selectedItems: $scope.mySelections
};

$scope.changeDelete = function () {
    $log.debug('Selection length = ' + $scope.mySelections.length);
    if ($scope.mySelections.length > 0) {
        $location.path("/EREditHospitalChange/");
    }
    $location.path("/EREditHospitalChange/LYNDA");

}

// mySelections.length 始终为 0。

他在 html 页我的网格声明:

<div ui-grid="gridOptions" ui-grid-selection ui-grid-pagination ui-grid-edit class="grid"></div>

<pre>{{mySelections}}</pre>
</fieldset>
<button ng-click="changeDelete()">Change/Delete</button>

[] This is what is visible in {{mySelections}}

尝试使用:

$scope.gridOptions = your grid options

$scope.gridOptions.onRegisterApi = function (gridApi) {
     $scope.gridApi = gridApi;
}
$scope.delete = function() {
    var rows = scope.gridApi.selection.getSelectedRows();
}

这些或那种方式在 $scope.gridApi.* 如果您尝试获得 ithe 复选框选择

您应该使用 gridApi.selection。请参阅 http://ui-grid.info/docs/#/api/ui.grid.selection.api:PublicApi and the tutorial: http://ui-grid.info/docs/#/tutorial/210_selection

处的文档

在您的 gridOptions 中,添加:

$scope.mySelections = [];

$scope.gridOptions = {
    enableRowSelection: true,
    enableRowHeaderSelection: false,
    modifierKeysToMultiSelect: true,
    multiSelect: true,
    pagingPageSize: 25,
    useExternalPagination: true,
    useExternalSorting: true,
    // Addition:
    onRegisterApi: function (gridApi) {
        $scope.gridApi = gridApi;
        gridApi.selection.on.rowSelectionChanged($scope,function(rows){
            $scope.mySelections = gridApi.selection.getSelectedRows();
        });
    }
};

这是一个关于 Plunker 的工作示例:http://plnkr.co/edit/u5pzISURTnvPBm9FyiLr?p=preview

您也可以删除 $scope.gridOptions = { },因为像您之后使用属性

一样声明对象是完全有效的