gpt4 book ai didi

javascript - ngOptions 创建空下拉列表

转载 作者:行者123 更新时间:2023-11-30 16:41:17 28 4
gpt4 key购买 nike

我正在尝试创建一个下拉菜单,但是当它加载时,我得到一个空的下拉选择框。

我正在使用以下 html:

<tr ng-repeat="i in data.suggestions">
<td>
<select ng-model="i.selYears" ng-options="selYears for val in selYears"></select>
</td>
</tr>

有了这些数据:

[
{
"years": [1, 2, 5]
},
{
"years": [1, 2, 5]
},
{
"years": [1, 2, 5]
}
]

是我的数据结构有问题,还是 ng-options 有问题?

这是我希望最终输出的样子:

<tr>
<td>
<select>
<option value="1">1 year</option>
<option value="2" selected="selected">2 years</option>
<option value="5">5 years</option>
</select>
</td>
</tr>
<tr>
<td>
<select>
<option value="1">1 year</option>
<option value="2" selected="selected">2 years</option>
<option value="5">5 years</option>
</select>
</td>
</tr>
<tr>
<td>
<select>
<option value="1">1 year</option>
<option value="2" selected="selected">2 years</option>
<option value="5">5 years</option>
</select>
</td>
</tr>

最佳答案

下面的代码应该可以工作

  <select ng-options="y.years as y.years for y in selYears" ></select>

假设 selYears 是 $scope 上的一个属性,例如

 $scope.selYears = [
{
"years": [1, 2, 5]
},
{
"years": [1, 2, 5]
},
{
"years": [1, 2, 5]
}

关于javascript - ngOptions 创建空下拉列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31948841/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com