我正在用Angular JS创建一个动态矩阵,在矩阵的每个单元格中都有一个输入文本框,我能够为每个文本框字段生成ng-model的动态名称。但我想根据选择框中选择的选项填充每个输入框的值。在ng-change上我调用了一个更新输入框的函数,但由于动态的ng-model名称,我很擅长为它们赋值。请参阅我的Html:
<table id="hq-matrix-table" class="table table-bordered">
<thead>
<tr class="column-label">
<td>#</td>
<td ng-repeat="column in columns">[[column]]</td>
</tr>
</thead>
<tbody class="price-matrix-table">
<tr ng-repeat="row in rows">
<td class="row-label">[[row]]</td>
<td ng-repeat="column in columns" >
<div class="input-group" ng-hide="column == '0' && row =='0'">
<span class="input-group-addon">$</span>
<input ng-model="cells[[row +''+ column]]" id="cell.[[ row ]]_[[column ]]" ng-class="myVar" ng-click ="myVar='input-matrix'" placeholder="No Price" type="text" class="form-control" />
</div>
</td>
</tr>
</tbody>
</table>
并选择框更改
<select ng-change="updateMatrixCells(section.costPerOption, [[section.id]] )" id="select[[section.id]]" name="costPerOption" ng-model="section.costPerOption" id="costPerOption" class="form-control selectpicker" data-live-search="true" onchange="$(this).selectpicker('refresh');">
<option ng-repeat="cost in readyCosts" value="[[ cost.value ]]" >[[ cost.name ]]</option>
答案 0 :(得分:0)
您可以使用row $ index和column $ index来获取要更新的确切单元格
<input ng-model="cells[$parent.$index][$index]" ng-class="myVar"
ng-click ="myVar='input-matrix'" placeholder="No Price"
type="text" class="form-control" />