将选定的行更新为ng-grid [英] Updating selected rows into ng-grid
本文介绍了将选定的行更新为ng-grid的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在更新selectedItems的列表,但用户界面上的选择(复选框)没有得到更新。
I am updating the list of selectedItems but the selections (checkboxes) on the UI are not getting updated for the same.
index.html
index.html
<body ng-controller="MyCtrl">
<div class="gridStyle" ng-grid="gridOptions"></div>
<h3>Rows selected</h3>
<pre>{{selectedRows}}</pre>
<button ng-click="selectAdam()">Select Adam</button>
</body>
main.js
var app = angular.module('myApp', ['ngGrid']);
app.controller('MyCtrl', function($scope) {
$scope.myData = [{name: "Sam", age: 50},
{name: "Peter", age: 43},
{name: "Jacob", age: 27},
{name: "Scott", age: 29},
{name: "Adam", age: 34}];
$scope.selectedRows = [];
$scope.gridOptions = { data: 'myData',
showSelectionCheckbox: true,
selectedItems: $scope.selectedRows
};
$scope.selectAdam = function() {
$scope.selectedRows.push({name: "Adam", age:34});
}
});
我在这里缺少什么?
推荐答案
显然这是你的工作方式(根据 ngGrid :
Apparently this is how you do it (based on the example at ngGrid:
$scope.selectAdam = function() {
angular.forEach($scope.myData, function(data, index){
if(data.name == 'Adam' && data.age == 34){
$scope.gridOptions.selectItem(index, true);
}
});
}
: http://plnkr.co/edit/K7b2ElQ1Z5uNAijFk7x4?p=info][1
这篇关于将选定的行更新为ng-grid的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文