产生的复选框,我已经建立了包含附着有ID和国家代码的国家的列表的JSON:勘定NG-模型伍重复
它看起来像这样:
$scope.countries = [
{"name":"Afghanistan","id":"AFG","country-code":"004"},
{"name":"Åland Islands","id":"ALA","country-code":"248"},
{"name":"Albania","id":"ALB","country-code":"008"},
{"name":"Algeria","id":"DZA","country-code":"012"}
]
我然后使用ng-repeat
指令为每个国家创建复选框输入。
<div ng-repeat="country in countries">
<label><input type="checkbox" ng-model="{{country.id}}" ng-true-value="'{{country.name}}'" ng-false-value="''">{{country.name}}</label>
</div>
然而,当我运行的代码我只得到了以下内容显示:
位置 复选框这里{{country.name}}
如果我删除的重复我的复选框产生很好,但我需要的ng-model
部分一个独特的ng-model
要附加到每个复选框
ng-model="{{country.id}}"
如何LD我去附加一个独特的ng-model
值?
这个答案(Generate ng-model inside ng-repeat)不提供独特的ng-model
值
尝试删除'{{}}'周围的'{{国家.id}}' – simeg
当我这样做时,我得到的所有复选框都是相同的ng-model值,但是我需要为每个复选框设置一个唯一的ng-model值。 – ocajian
尝试将'ng-repeat'设置为'country in country track by $ index '和'ng-model'到'countries [$ index]' – simeg