我可以用NG-重复迭代在AngularJS一个数组? [英] Can I use ng-repeat to iterate over an array in AngularJS?
问题描述
我有一些麻烦,使用AngularJS纳克重复。以下是我有:
< DIV NG:秀=选择== 3>
< DIV CLASS =列>
&所述; textarea的行=4数据纳克模型=modal.data.answer [1]的.textCOLS =91→1&下; / textarea的>
< / DIV>
< DIV CLASS =列>
<标签>说明及LT; /标签>
&所述; textarea的行=2数据纳克模型=modal.data.answer [1] .explanationCOLS =91>&下; / textarea的>
< / DIV>
< DIV CLASS =列>
< DIV CLASS =colx2左>
<跨度类=标签>正确< / SPAN>
<输入类型=复选框数据-NG-模式=modal.data.answer [1] .correct级=复选框><输入类型=隐藏值=假名称= 细节[0] .Correct>
< / DIV>
< DIV CLASS =colx2右>
<标签>图像文件< /标签>
<输入类型=文本数据-NG-模式=modal.data.answer [1]形象CLASS =全角>
< / DIV>
< / DIV>
< / DIV>
该modal.data.answer数组总是有六个要素。我可以用NG-重复创建这些HTML和有它在阵列中重复甚至[X]数字和有它递增为选择=第一行中的数字从3到8?
据我知道我可以使用< DIV NG重复=吨[3,4,5,6,7,8]> < / DIV>
但我怎么能得到T的值代入这样的话:
数据-NG-模式=modal.data.answer [1]的.text
,你可以通过一个整数列表迭代简便,您只需使用你的索引值像
< DIV NG重复=吨[3,4,5,6,7,8]>
....
数据-NG-模式=modal.data.answer [T]的.text
...
我做了一个小提琴,如果你想尝试 http://jsfiddle.net/DotDotDot/tweyS/ (输入场就在这里更改选定的值,因为你的code样品中,以显示正确的字段)
有乐趣
I am having some trouble with using AngularJS ng-repeat. Here is what I have:
<div ng:show="selected == 3">
<div class="columns">
<textarea rows="4" data-ng-model="modal.data.answer[1].text" cols="91">1</textarea>
</div>
<div class="columns">
<label>Explanation</label>
<textarea rows="2" data-ng-model="modal.data.answer[1].explanation" cols="91"></textarea>
</div>
<div class="columns">
<div class="colx2-left">
<span class="label">Correct</span>
<input type="checkbox" data-ng-model="modal.data.answer[1].correct" class="check-box"><input type="hidden" value="false" name="Details[0].Correct">
</div>
<div class="colx2-right">
<label>Image File</label>
<input type="text" data-ng-model="modal.data.answer[1]image" class="full-width">
</div>
</div>
</div>
The modal.data.answer array will always have six elements. Can I use ng-repeat to create the HTML for these and have it repeat even the [x] numbers in the array and have it increment the number on the first line for "selected =" from 3 to 8 ?
As far as I know I can use <div ng-repeat="t in [3,4,5,6,7,8]"> </div>
but how can I get the values of t into things like:
data-ng-model="modal.data.answer[1].text"
your edit is heading in the right way, you can iterate through a list of integers easily, the you just use the value of you index like that
<div ng-repeat="t in [3,4,5,6,7,8]">
....
data-ng-model="modal.data.answer[t].text"
...
I made a fiddle if you want to try http://jsfiddle.net/DotDotDot/tweyS/ (the input field is just here to change the selected value, as in your code sample, in order to display the right fields)
have fun
这篇关于我可以用NG-重复迭代在AngularJS一个数组?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!