我希望您能将选择选项填充为基本json数组中的值,并使内容更加通俗易懂。 我们以国家选择为例。每个国家都有一个id元素和一个名称,还有其他我可以忽略的字段。 基本上,我想在
value = ""
字段中放置一个值,在<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 fiddle中。 我觉得我漏掉了什么。
value="{{country.countryId}}"
的值。 - vamsikrishnamannemng-options
。 - Wtower