一尘不染

从ng-grid获取选择行?

angularjs

如何在ng-grid中创建(或访问)选定行的数组?


文档(滚动到“网格选项”)

id                 | default value | definition
-----------------------------------------------
selectedItems      |       []      | all of the items selected in the grid.
                                     In single select mode there will only
                                     be one item in the array.

index.html

<body ng-controller="MyCtrl">
    <div class="gridStyle" ng-grid="gridOptions"></div>

    <h3>Rows selected</h3>
    <pre>{{selectedItems}}</pre>
</body>

main.js

var app = angular.module('myApp', ['ngGrid']);
app.controller('MyCtrl', function($scope) {
    $scope.myData = [{name: "Moroni", age: 50},
                     {name: "Tiancum", age: 43},
                     {name: "Jacob", age: 27},
                     {name: "Nephi", age: 29},
                     {name: "Enos", age: 34}];
    $scope.gridOptions = { data: 'myData' };
});

Plnkr代码(并运行它)


阅读 385

收藏
2020-07-04

共1个答案

一尘不染

根据文档,selectedItems应该是的属性$scope.gridOptions,因此请尝试以下操作:

控制者

$scope.gridOptions = { data: 'myData', selectedItems: [] };

的HTML

<pre>{{gridOptions.selectedItems}}</pre>
2020-07-04