angular ng-repeat 中的 js 动态复选框
angular js dynamic checkbox in ng-repeat
我有服务 table,我喜欢
ID Text
1 Cleaning
2 Washing
3 Folding
4 Drying
我使用 api 调用检索它们并得到了 Json。我有另一个 table,其中我有这些服务的价格以及产品 ID,因此在添加产品时我想添加服务及其价格。为此,我使用 api 调用检索派生和 ID,并在 table 中迭代它们,并使用相同的迭代生成文本框以输入特定服务的价格。这是我绞尽脑汁做出来的table
<table id="dataTable" class="table table-striped table-bordered table-hover">
<thead>
<tr>
<th>
Service
<i class="fa sort"></i>
</th>
<th>
Price
<i class="fa sort"></i>
</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="Record in ServiceList">
<td>
<span>
<input id={{Record.ID}} ng-model="Services[Record.ID]" ng-checked="Record.ID==ProductProfile.PriceList.ServiceID" type="checkbox">
<label for={{Record.ID}}>
{{Record.Text}}
</label>
</span>
</td>
<td><span> <input id={{Record.ID}} ng-model="PriceList[Record.Price]" ng-disabled="!Services[Record.ID]" class="col-lg-12" type="number"></span></td>
</tr>
</tbody>
场景最初是所有复选框(取决于服务中的服务数量table)都未选中并且文本框被禁用用户可以勾选所需的服务这将在用户保存后启用相应的文本框记录所选服务的列表及其价格将在 ProductProfile.PriceList 中,其中有两个属性 ServiceID 和 Price
我试图通过在我的控制器中使用 for 循环来做到这一点,但失败了
我
完成了
<div class="col-lg-8">
<table id="dataTable" class="table table-striped table-bordered table-hover">
<thead>
<tr>
<th>
Service
<i class="fa sort"></i>
</th>
<th>
Price
<i class="fa sort"></i>
</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="Record in ServiceList">
<td>
<span>
<input id={{Record.ServiceID}} ng-model="Record.IsExist" type="checkbox">
<label for={{Record.ServiceID}}>
{{Record.Text}}
</label>
</span>
</td>
<td><span> <input ng-model="Record.Price" ng-disabled="!Record.IsExist" class="col-lg-12" step="any" min="0" max="1000" type="number"></span></td>
</tr>
</tbody>
</table>
</div>
我有服务 table,我喜欢
ID Text
1 Cleaning
2 Washing
3 Folding
4 Drying
我使用 api 调用检索它们并得到了 Json。我有另一个 table,其中我有这些服务的价格以及产品 ID,因此在添加产品时我想添加服务及其价格。为此,我使用 api 调用检索派生和 ID,并在 table 中迭代它们,并使用相同的迭代生成文本框以输入特定服务的价格。这是我绞尽脑汁做出来的table
<table id="dataTable" class="table table-striped table-bordered table-hover">
<thead>
<tr>
<th>
Service
<i class="fa sort"></i>
</th>
<th>
Price
<i class="fa sort"></i>
</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="Record in ServiceList">
<td>
<span>
<input id={{Record.ID}} ng-model="Services[Record.ID]" ng-checked="Record.ID==ProductProfile.PriceList.ServiceID" type="checkbox">
<label for={{Record.ID}}>
{{Record.Text}}
</label>
</span>
</td>
<td><span> <input id={{Record.ID}} ng-model="PriceList[Record.Price]" ng-disabled="!Services[Record.ID]" class="col-lg-12" type="number"></span></td>
</tr>
</tbody>
场景最初是所有复选框(取决于服务中的服务数量table)都未选中并且文本框被禁用用户可以勾选所需的服务这将在用户保存后启用相应的文本框记录所选服务的列表及其价格将在 ProductProfile.PriceList 中,其中有两个属性 ServiceID 和 Price
我试图通过在我的控制器中使用 for 循环来做到这一点,但失败了
我
完成了 <div class="col-lg-8">
<table id="dataTable" class="table table-striped table-bordered table-hover">
<thead>
<tr>
<th>
Service
<i class="fa sort"></i>
</th>
<th>
Price
<i class="fa sort"></i>
</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="Record in ServiceList">
<td>
<span>
<input id={{Record.ServiceID}} ng-model="Record.IsExist" type="checkbox">
<label for={{Record.ServiceID}}>
{{Record.Text}}
</label>
</span>
</td>
<td><span> <input ng-model="Record.Price" ng-disabled="!Record.IsExist" class="col-lg-12" step="any" min="0" max="1000" type="number"></span></td>
</tr>
</tbody>
</table>
</div>