AngularJS递增嵌套中继器中项目的id值
AngularJS increment id value of items in nested repeater
我有下面的代码,其中有问题和选择,我需要这些选择增加id值。
然而,每次出现新问题时,我都需要增量来重新开始。到目前为止,我发现的大多数例子都是增量的(例如使用$index)。但我在SO上看了几篇文章,比如这篇,但没有得到我需要的结果:
我需要的是:
Question 1
Choice10 (the first numerical value is the Id of the question,
Choice11 the second numerical value should be the incremented id)
Choice12
Question 2
Choice20
Choice21
Choice22
Choice23
html代码如下所示:
<table summary="" style="border: none; width: 100%; background: none;" id="rptQuestions">
<tbody>
<tr style="width: 100%;" ng-repeat-start="q in questions track by $index">
...Question details here...
</tr>
<tr>
<td class="Bold_10" colspan="4">
<table summary="" style="border: none; background: none">
<tbody>
<tr ng-repeat-start="c in choices" ng-if="c.QuestionId==q.QuestionId">
<td style="width: 2em;"><a href="javascript:void(0);" ng-click="DeleteChoice(c)">X</a></td>
<td>
<input type="text" id="inLetter{{c.QuestionId}}{{ value?? }}" ng-model="c.Letter" style="width: 2em;" /></td>
<td style="text-align: left;">
<input type="text" id="inChoice{{c.QuestionId}}{{ value?? }}" ng-model="c.Choice" style="width: 60em;" /> <input type="hidden" id="inChoiceId{{c.QuestionId}}{{ value?? }}" ng-value="{{c.Id}}" /></td>
</tr>
<tr ng-repeat-end ng-if="c.QuestionId==null"><td colspan="3"></td></tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
<table summary="" style="border: none; width: 100%; background: none;" id="rptQuestions">
<tbody>
<tr style="width: 100%;" ng-repeat-start="q in questions">
...Question details here...
</tr>
<tr ng-repeat-end="">
<td class="Bold_10" colspan="4">
<table summary="" style="border: none; background: none">
<tbody>
<tr ng-repeat-start="c in choices" ng-if="c.QuestionId==q.QuestionId">
<td style="width: 2em;"><a href="javascript:void(0);" ng-click="DeleteChoice(c)">X</a></td>
<td>
<input type="text" id="inLetter{{$parent.$index}}{{$index}}" ng-model="c.Letter" style="width: 2em;" /></td>
<td style="text-align: left;">
<input type="text" id="inChoice{{$parent.$index}}{{$index}}" ng-model="c.Choice" style="width: 60em;" /> <input type="hidden" id="inChoiceId{{$parent.$index}}{{$index}}" ng-value="{{c.Id}}" /></td>
</tr>
<tr ng-repeat-end ng-if="c.QuestionId==null"><td colspan="3"></td></tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
每个ng重复都有自己的索引,您可以从嵌套循环中访问该索引。但是,请注意,在您的实现中,Choice111中的id可能会产生误导。
问题1.11==问题11.1
相关文章:
- Redux处理新项目和id
- 如何在angular js中的select选项中获取所选项目id
- 使用 id 和 Javascript 从数组中删除项目
- jQuery 使用 ID 作为 URL 选择一个项目
- id:在续集中创建新项目时为空
- 点击事件:选择要按 ID 点击的项目
- 如何选择不包含类/id 的项目 - jquery.
- 如何查找 Outlook 邮件项目 ID 号
- 克隆项目时,是否可以更改所有输入属性和 ID,如下所示;
- 隐藏在正文单击EXPT项目ID =某物
- Jquery - 按 ID 选择项目不起作用
- extjs3.4:如何访问面板中没有 id/itemId 的项目
- 如何将项目id传递给我的控制器以进行删除方法
- 为什么这个JS id不适用于多个项目
- 正在添加项目id's到js-if语句
- 使用javascript在devexpress组合框中获取所选项目id
- 唯一ID和动态添加的项目的棘手情况
- 如何通过输入项目的id或序列在列表项目的文本中查找值
- 循环遍历数组中的项目以分配 data-id,但仅获取数组中的最后一项
- 我想插入和更新特定项目id的数量