angularjs - 验证 ng-repeat 表中的选择选项
问题描述
如果所有选择选项都为空,我想验证或检查 ng-repeat 表中的选择数组选项。然后,假设 2 选择选项是否具有值如何获取这些值。在此先感谢,非常感谢您的帮助。
html
<button type="button" ng-click="checkSelect()">Check</button>
<button type="button" ng-click="getvalue()">get</button>
<table><tr ng-repeat="x in names">
<td>{{ x.Name }}</td>
<td>
<select ng-model="person.numPerson[$index]" ng-options="num for num in [] | range:5">
<option value="">0</option>
</select>
</td></tr></table>
js
var app = angular.module('app', []);
app.controller('Controller', function($scope, $http){
//for validation
$scope.checkSelect = function () {
}
//get all selected select value
$scope.getvalue = function () {
}
});
解决方案
请使用以下更新您的 checkSelect 功能
//for validation
$scope.checkSelect = function () {
angular.forEach($scope.person.numPerson, function(value, key) {
if(value == ''){
//Show alert or maintain a flag to show error to users
//perform actions
}
});
}
推荐阅读
- javascript - 从 Chrome DevTools 执行现有的 JS 函数
- css - 在 `font-face` 声明中包含长行的 `data` URI
- node.js - 如何自动将我的 Loopback 3 升级到 Loopback 4?
- java - 由于 JVM 崩溃,在 Drools 中禁用 JIT
- python - 如何针对输入数组运行函数?
- angular - 使用 Rxjs 过滤器和映射进行数组迭代
- java - Spring Boot FreeMarker:如何动态使用自定义模板?
- nuxt.js - Nuxtjs 不在产品环境中获取数据
- android - 在字符串值android中存储小数字符
- mysql - 优化运行缓慢的 3 个表的 mysql 连接