从 ng-grid 中选择行? [英] Getting select rows from ng-grid?
本文介绍了从 ng-grid 中选择行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在我的 ng-grid中创建(或访问)选定行的数组一个>?
文档(滚动到网格选项")
id |默认值 |定义-----------------------------------------------选定项目 |[] |在网格中选择的所有项目.在单选模式下只会有是数组中的一项.
index.html
<div class="gridStyle"ng-grid="gridOptions"></div><h3>选择的行</h3><pre>{{selectedItems}}</pre>
main.js
var app = angular.module('myApp', ['ngGrid']);app.controller('MyCtrl', function($scope) {$scope.myData = [{name: Moroni", age: 50},{名称:Tiancum",年龄:43},{姓名:雅各",年龄:27},{姓名:尼腓",年龄:29},{名称:以诺斯",年龄:34}];$scope.gridOptions = { 数据:'myData' };});
Plnkr 代码(并运行它)
解决方案
根据文档,selectedItems
应该是 $scope.gridOptions
的一个属性,所以试试这个:
控制器
$scope.gridOptions = { data: 'myData', selectedItems: [] };
HTML
{{gridOptions.selectedItems}}
How do I create (or access) an array of selected rows in my ng-grid?
Documentation (scroll to "Grid options")
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 for the code (and to run it)
解决方案
Based on the doc, selectedItems
should be a property of $scope.gridOptions
, so try this:
Controller
$scope.gridOptions = { data: 'myData', selectedItems: [] };
HTML
<pre>{{gridOptions.selectedItems}}</pre>
这篇关于从 ng-grid 中选择行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文