angularjs - 如何针对表格行单独获取值或下拉列表和文本框 - AngularJS
问题描述
我正在使用具有动态行数的表格,每一行都将包含下拉列表和输入文本框的组合。我关心如何获取特定于相应行的文本框和下拉列表的值。
我尝试获取下拉列表的值,例如:
HTML:
<td>
<select class="custom-select" ng-model="selectionModel[row.number]"
ng-change="optionChanged(row.number, selectionModel[row.number])"
ng-options="choice.name for choice in possibleOptions track by choice.id">
</select>
</td>
JS:
$scope.selectionModel = {};
angular.forEach($scope.record, function(cus) {
$scope.selectionModel[cus.number] = $scope.possibleOptions.filter(function(opt) {
return opt.id === cus.option;
})[0];
});
function getUniqueValues(array, prop) {
return [...new Set(array.map(item => item[prop]))];
}
在下拉更改中,我创建了一个函数来捕获值是否已更改,并将更改的值存储在数组中。这现在工作正常。
我现在对如何为文本框做同样的事情有点困惑。如何针对表格行单独获取文本框的值?
我的文本框看起来像:
<td>
<input type="text" class="form-control" style="font-size:0.9rem !important;"
id="commentsId" placeholder="Comments" ng-model="comments"
ng-bind="row.comments"/>
</td>
请指导。
解决方案
推荐阅读
- c# - 循环遍历 C# 中的网格按钮以计算黑色方块
- vue.js - 用 jest 进行 Vue 测试:$route 始终未定义
- vue.js - Router.beforeEach 跳转回登录页面,登录后重置vuex状态值
- java - 如何在spring boot中将对象从jsp传递到控制器
- javascript - Javascript - 数组的第一个元素返回未定义
- .net - .Net 核心和基于角色的授权
- ios - iOS corebluetooh 在后台做广告
- logging - 如何格式化 Azure DevOps 控制台日志
- rust - 如何在 Rust 中将 impl<'a> From<&'a Method> 用于 &'a str?
- javascript - 为什么使用 onclick 在 location.reload() 之后返回 false?