AngularJS用JSON填充选择选项 [英] Angularjs populate select options with json
本文介绍了AngularJS用JSON填充选择选项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在寻找从基本json数组中填充值的选择选项.
I am looking to populate select option with values from a basic json array.
我的示例是一个国家/地区选择.每个国家/地区都有一个id元素和一个名称以及其他我可以忽略的字段.基本上我想说的是,将一个值放在value=""
字段中,将另一个值放在<option>tags</option>
The example I have is a country select. Each country has an id element and a name plus other fields that I can ignore. Basically I would like to say put one value in the value=""
field and another between the <option>tags</option>
html代码段
<div ng-controller="DemoCtrl">
<p>populate select options with ajax</p>
<select id="Country" name="Country" class="form-control" size="10"
ng-model ="chooseCountries">
<option ng:repeat="country in chooseCountries" value="{{country.id}}">
{{country.name}}
</option>
</select>
</div>
javascript代码段
'use strict';
function DemoSelectCtrl($scope) {
$scope.chooseCountries=[
{countryId : 1, name : "France - Mainland", desc: "some description" },
{countryId : 3, name : "Gibraltar", desc: "some description"},
{countryId : 3, name : "Malta", desc: "some description"}
];
});
我将其放在这里 js小提琴 .我错过了一些东西
I have put it together here js fiddle.. I think I'm missing something
推荐答案
-
angular.module('ui.bootstrap.demo', ['ui.bootstrap'])
-确保您具有ui.bootstrap.阅读如何安装它 http://angular-ui.github.io/bootstrap/ - 这是您更新的jsfiddle http://jsfiddle.net/e31k5e6L/1/
angular.module('ui.bootstrap.demo', ['ui.bootstrap'])
- be sure you have ui.bootstrap. Read how to install it http://angular-ui.github.io/bootstrap/- Here is your updated jsfiddle http://jsfiddle.net/e31k5e6L/1/
这篇关于AngularJS用JSON填充选择选项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文