1 回答

TA貢獻(xiàn)1780條經(jīng)驗(yàn) 獲得超1個贊
這里的問題是你有一個值列表,但只有一個布爾值代表所有這些值。
tableRowTrueOrFalse應(yīng)該是布爾值數(shù)組而不是布爾值。然后你應(yīng)該用默認(rèn)值填充數(shù)組false。
$scope.tableRowTrueOrFalse = Array(availableFields.length).fill(false);
在你的 html 中,它會是這樣的:
<table>
<tbody ng-repeat="field in availableFields">
<tr ng-class="{'orderTypeTableRowSelected':tableRowTrueOrFalse[$index]}">
<td style="padding:3px;">{{field.name}}</td>
<td style="padding:3px;">
<button type="button" ng-click="orderTypeTableRowSelected(field, $index)" class="btn btn-danger" style="margin-left:10px;"><i class="fas fa-check"></i> Required</button>
<button type="button" class="btn btn-warning"><i class="fas fa-check"></i> Default </button>
</td>
</tr>
</tbody>
</table>
然后在你的函數(shù)中,
$scope.orderTypeTableRowSelected = function (field, index) {
$scope.tableRowTrueOrFalse[index] = !$scope.tableRowTrueOrFalse[index];
console.log(field);
};
- 1 回答
- 0 關(guān)注
- 107 瀏覽
添加回答
舉報(bào)