javascript 使用 Angularjs 将数组值设置为 Dropdown
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/21426210/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Set array value to Dropdown using Angularjs
提问by Hulk1991
I am newbie to Angularjs. Here is my scenario.
我是 Angularjs 的新手。这是我的场景。
I have an array of
我有一个数组
numbers = ['1','2','3'];
numbers = ['1','2','3'];
And also have a
并且还有一个
<select id="fileNumber" ng-model="files"></select>
<select id="fileNumber" ng-model="files"></select>
How Can I add the values of array to the dropdown list fileNumber
如何将数组的值添加到下拉列表中 fileNumber
I tried,
我试过,
ng-options="numbers"
ng-options="numbers"
Can anyone say how to include array value to dropdown list.
任何人都可以说如何将数组值包含到下拉列表中。
回答by Alex Choroshin
Here's an example for working with select and adding values to array:
下面是一个使用 select 并将值添加到数组的示例:
Update:
更新:
<select ng-model='selectedNumber' ng-options='number for number in numbers'></select>
<button ng-click="add()">add</button>
Live example: http://jsfiddle.net/choroshin/MTfRD/643/
回答by RaviH
Read and follow ng-select directive
阅读并遵循ng-select 指令