angular.js - 關(guān)于ng-option的用法
問題描述
數(shù)據(jù)是這樣的

那我如果用ng-option怎么循環(huán)出來這些數(shù)據(jù)
現(xiàn)在代碼是這樣的:
<p class='am-form-group'> <label class='am-u-sm-3 am-u-md-3 am-u-lg-2 am-form-label am-text-right'>導(dǎo)演國籍:</label> <p class='am-u-sm-9 am-u-md-9 am-u-lg-10'><select ng-model='selected_cn_0' name='film[nationality]'> <option value='{{$index}}' ng-repeat='country in countrys_0'>{{country}}</option></select><span class='am-form-caret'></span> </p></p>
控制器:
$scope.countrys_1 = data.nationality;$scope.selected_cn_1 = data.nationality[46];
我想讓option的value是 下標(biāo),不知道怎么改,默認(rèn)顯示為第46條數(shù)據(jù)的值
問題解答
回答1:html:
<select ng-model='selected_cn_1' ng-options='value for (key,value) in countrys_1'></select>
js
$scope.countrys_1 = data.nationality;$scope.selected_cn_1 = data.nationality[46];//通過ng-model和select綁定
ng-options的用法
回答2:<p class='am-form-group'><label class='am-u-sm-3 am-u-md-3 am-u-lg-2 am-form-label am-text-right'>導(dǎo)演國籍:</label><p class='am-u-sm-9 am-u-md-9 am-u-lg-10'> <select ng-model='selected_cn_0' number name='film[nationality]'><option value='{{k}}' ng-repeat='(k, v) in countrys_0'>{{v}}</option> </select> <span class='am-form-caret'></span></p> </p>
convert-to-number
//http://stackoverflow.com/a/35407627/2586541 app.directive(’number’, function () {return { require: ’ngModel’, link: function (scope, element, attrs, ngModel) {//valuengModel.$parsers.push(function (val) { //return ’’ + val; return parseInt(val, 10);});//showngModel.$formatters.push(function (val) { //return parseInt(val, 10); return ’’ + parseInt(val || 0, 10);}); }}; });
相關(guān)文章:
1. docker gitlab 如何git clone?2. docker網(wǎng)絡(luò)端口映射,沒有方便點的操作方法么?3. debian - docker依賴的aufs-tools源碼哪里可以找到啊?4. docker容器呢SSH為什么連不通呢?5. vim - docker中新的ubuntu12.04鏡像,運行vi提示,找不到命名.6. docker安裝后出現(xiàn)Cannot connect to the Docker daemon.7. docker-compose 為何找不到配置文件?8. 為什么我ping不通我的docker容器呢???9. mac連接阿里云docker集群,已經(jīng)卡了2天了,求問?10. golang - 用IDE看docker源碼時的小問題

網(wǎng)公網(wǎng)安備