javascript - angularJS使用ng-repeat 生成tr如何通过复选框选定
本文介绍了javascript - angularJS使用ng-repeat 生成tr如何通过复选框选定的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
问 题
代码如下:
<!DOCTYPE html>
<html lang="en" ng-app="exampleApp">
<head>
<meta charset="UTF-8">
<title>Title</title>
<script src="active/jquery.min.js"></script>
<script src="active/angular.min.js"></script>
<script>
angular.module("exampleApp",[])
.controller("default",function ($scope) {
$scope.items = [
{name:"zhou",age:25},
{name:"li",age:40},
{name:"zhu",age:27}
];
})
</script>
</head>
<body ng-controller="default">
<table>
<thead><tr><th>#</th><th>姓名</th><th>年龄</th></tr></thead>
<tbody >
<tr ng-repeat="item in items">
<td><input type="checkbox" /></td>
<td>{{item.name}}</td>
<td>{{item.age}}</td>
</tr>
</tbody>
</table>
</body>
</html>
如何得到我已经选择的两行数据
解决方案
<tr ng-repeat="item in items">
<td><input type="checkbox" value="{{item}}" name="test" "/></td>
<td>{{item.name}}</td>
<td>{{item.age}}</td>
</tr>
js部分
var inputEle = angular.element("input:checkbox[name='test']:checked");
var temp = [];
angular.forEach(inputEle,function(item){
//按需去对应的数据
var itemValue = angular.fromJson(item.value);
temp.push(item)
})
这篇关于javascript - angularJS使用ng-repeat 生成tr如何通过复选框选定的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文