选择多个复选框并将值分配给数组 - HTML/Javascript
Selecting multiple checkboxes and assigning values into array - HTML/Javascript
我有一个模式对话框,在名称旁边显示一个复选框表。我想分配这些复选框以选择该名称的值(即,当我选中表格上"Jon"旁边的框时,我希望选中该名称)。当我单击多个复选框时,我想将其作为数组传递给 javascript。
本质上:单击名称旁边的复选框 ->选择的名称 ->在对话框中按"确定" ->将数组中名称的ID发送到JS代码
网页代码:
</div>
<div class="modal-body">
<table class="table table-striped table-hover ">
<thead>
<tr>
<th>Select</th>
<th>User Name</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="user in users" ng-hide="user.name === lic.users.name">
<td><input type="checkbox" ng-model="user.selected" id="userId"/></td>
<td>{{user.name}}</td>
</tr>
</tbody>
</table>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default btn-sm" data-dismiss="modal">Cancel</button>
<button type="button" class="btn btn-primary btn-sm" ng-click="addLicUser(userId, lic.license.id)">Ok</button>
</div>
</div>
<div class="modal" id="add-new-lic-user">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h4 class="modal-title">Add License User</h4>
</div>
<div class="modal-body">
<p>Are you sure you want to add these users to this license?</p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default btn-sm" data-dismiss="modal">Cancel</button>
<button type="button" class="btn btn-primary btn-sm" ng-click="processLicenseUser">Ok</button>
</div>
</div>
</div>
Javascript:
$scope.addLicenseUser = function (){
$("#add-lic-user").modal('show');
};
$scope.addLicUser = function (usId, licId){
$scope.licenseId = licId;
$scope.userIdToAdd = usId;
$("#add-lic-user").modal('hide');
$("#add-new-lic-user").modal('show');
};
$("#processLicenseUser").click(function(e){
e.preventDefault();
$scope.processLicenseUser();
});
$scope.processLicenseUser = function () {
usId.forEach(function(entry){
//
var req = {
method: 'POST',
url: '/rest/v1/porta/mapping',
headers:{
'Content-Type': 'application/json',
'GoverlanHeader_1': 'Yes',
'x-access-token': $scope.authInfo.token
},
data: {'userId': $scope.userIdToAdd, 'licenseId': $scope.licenseId}
};
您已经绑定到每个用户的选定属性,您可以按该属性进行简单的筛选
$scope.processLicenseUser = function () {
var selected_users = [];
$scope.users.forEach(function(user) {
if user.selected {
selected_users.push({'userId': user.Id, 'licenseId': user.licenseId});
}
})
var req = {
method: 'POST',
url: '/rest/v1/porta/mapping',
headers:{
'Content-Type': 'application/json',
'GoverlanHeader_1': 'Yes',
'x-access-token': $scope.authInfo.token
},
data: selected_users
};
"我想把它作为一个数组传递给javascript。
在代码中的任何位置,您都不会将单击的项推送到数组中。
$scope.users = [];
$scope.checked = function() {
$scope.user.splice(0, $scope.user.length);
$scope.user.push('id');
};
});
相关文章:
- 使用Web Html表单创建Javascript数组
- 如何放置ÅÄ和#214;在javascript数组中,然后将其与html文本进行比较
- jQuery对象从html表中查询为两个一维数组,用于Chartist图表
- 正在转义javascript数组中的html字符
- 构建HTML选择字段并使用JavaScript数组选择选项
- 使用jQuery在html数组中设置一个值
- 如何在angular js/HTML中处理数组
- 如何将html中的列表项解析为javascript数组
- 如何查找给定数组中包含值的HTML元素
- 我想使用Javascript中的循环在HTML中的特定id中显示数组中的多个对象
- 如何使用angular指令从html中获取数组
- 如何将数组(Google应用程序脚本)返回到HTML侧边栏
- 每隔几秒钟从 html 中的数组中的值更改类
- 将 PHP 数组传递给 HTML 页面
- 在 HTML URL 中使用数组
- HTML 数组乘以 javascript
- 数组/HTML中的函数
- 选择多个复选框并将值分配给数组 - HTML/Javascript
- 在JavaScript中传递数组HTML元素
- 数组HTML Javascript中的图像