Angularjs,对表中选定的复选框应用操作 [英] Angularjs, Applying Action on Selected Checkboxes in Table
问题描述
我正在尝试学习 AngularJS 并且我正在实现这个复选框,当我从网格中删除一些复选框并单击删除按钮时,应从选定的复选框中删除表中的数据.
我尝试过,但不知道如何实现它.
请在Plunker上查看我的这段代码.http://plnkr.co/edit/e7r65Me4E7OIWZ032qKM?p=preview
如果你分叉并给出上述Plunker的工作示例,那就太好了.
一个简单的方法是将您的学生列表更改为:
$scope.students = [{Rollno: "1122",Name: "abc",Uni: "res", selected: false},{Rollno: "2233",Name: "def",Uni: "tuv", selected: false},{Rollno: "3344",Name: "ghi",Uni: "wxy", selected: false}];
与:
在视图中.通过将 filter
注入控制器,您可以重写 删除函数以:
$scope.remove = function(){$scope.students = filterFilter($scope.students, function (student) {返回 !student.selected;});};
这里是完整的代码:
(function (app, ng) {'使用严格';app.controller('TableCtrl', ['$scope', 'filterFilter', function($scope, filterFilter) {$scope.students = [{Rollno: "1122",Name: "abc",Uni: "res", selected: false},{Rollno: "2233",Name: "def",Uni: "tuv", selected: false},{Rollno: "3344",Name: "ghi",Uni: "wxy", selected: false}];$scope.save = function(){$scope.students.push({罗尔诺:$scope.new_rollno,名称:$scope.new_name,大学:$scope.new_uni});$scope.new_rollno = $scope.new_name = $scope.new_uni = '';};$scope.remove = function(){$scope.students = filterFilter($scope.students, function (student) {返回 !student.selected;});};}]);}(angular.module('app', []), angular));
/* 样式在这里 */桌子{宽度:100%;}表,th,td{边框:1px纯黑色;}.颜色{背景颜色:浅灰色;}.color2{背景颜色:白色;}#标题{背景颜色:黑色;白颜色;}tr:悬停{背景颜色:深蓝色;白颜色;字体粗细:粗体;}#images img{边距顶部:10px;}#img1{宽度:33.4%;}#img2{宽度:66%;高度:255px;}#表格1{边距顶部:10px;}标签{显示:块;底边距:5px;边距顶部:5px;}按钮{边距顶部:5px;填充:5px;}
<html ng-app="app"><头><script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.1.5/angular.min.js"></script><元字符集=utf-8/><title>JS Bin</title>头部><身体><div><label>搜索:</label><input type="search" ng-model="search" placeholder="Enter to Search">
<div id="table1" ng-controller="TableCtrl"><table cellpadding="0" border="0" cellspacing="0">
<div style="float: right; margin-right: 300px;margin-top: -200px;"><button ng-click="remove($index)">移除</button>