首页 > 解决方案 > 如何针对表格行单独获取值或下拉列表和文本框 - 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>

请指导。

标签: angularjs

解决方案


推荐阅读