0
我正在使用AngularJS和MVC。我有一個表的複選框,並代碼如下:如何在angularjs中的按鈕單擊事件上獲取選定的複選框值
<div class="table table-responsive">
<table class="table table-striped">
<thead>
<tr>
<th>
<input type="checkbox" checkbox-all="categories.isSelected" /></th>
<th>Category Name</th>
<th>Description</th>
<th></th>
</tr>
</thead>
<tbody>
<tr dir-paginate="category in categories | filter:search_txt | itemsPerPage: pageSize" current-page="currentPage">
<td style="padding-left: 9px; padding-top: 1px; padding-bottom: 1px; vertical-align: middle">
<div style="height: 35px; overflow: auto;">
**<input type="checkbox" ng-model="selected[category.categoryID]" />**
</div>
</td>
<td style="padding: 1px; vertical-align: middle">
<div style="height: 35px; overflow: auto;">{{category.categoryName}}</div>
</td>
<td style="padding: 1px; vertical-align: middle">
<div style="height: 35px; overflow: auto;">{{category.description}}</div>
</td>
<td style="padding: 1px; vertical-align: middle">
<div style="height: 35px; overflow: auto;">
<a class="btn btn-primary" href="#/category/{{category.categoryID}}" title="Edit">
<i class="glyphicon glyphicon-edit"></i></a>
</div>
</td>
</tr>
</tbody>
</table>
</div>
有一個超鏈接,單擊超鏈接將只需要檢查的值(的categoryID),並將它們發送到一個.js控制器。 按鈕控制是這樣的:
<a class="btn btn-danger" ng-click="removeSelectedRows()" ng-controller="categoryMultiDeleteController"><i class="glyphicon glyphicon-trash"></i> Delete</a>
控制器的代碼是這樣的:
myApp.controller('categoryMultiDeleteController',
['$scope', 'categoryDataService',
function ($scope) {
$scope.removeSelectedRows = function() {
$scope.categories = $.grep($scope.categories, function (category) {
return $scope.selected[category.categoryID];
});
}
}]);
我可以訪問上述的.js控制器但在爲目的的陣列的形式不能得到所檢查的值的刪除。
還有另一個.js文件,它就像一個「數據服務」,它最終將數組從controller.js文件發送到MVC控制器進行刪除。數據服務的代碼如下:
var _selectedRows = function (_categories) {
var deferred = $q.defer();
var controllerQuery = "category/DeleteMultipleCategory/" + _categories;
$http.post(controllerQuery)
.then(function (result) {
deferred.resolve();
},
function (error) {
// Error
deferred.reject();
});
return deferred.promise;
};
我的問題是我怎麼能得到複選框值從UI到angularJS控制器,並從那裏到一個數組的形式MVC控制器。