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)演國(guó)籍:</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)演國(guó)籍:</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. boot2docker無法啟動(dòng)2. 關(guān)docker hub上有些鏡像的tag被標(biāo)記““This image has vulnerabilities””3. docker-compose中volumes的問題4. javascript - mock.js可以存儲(chǔ)數(shù)據(jù)嗎5. nignx - docker內(nèi)nginx 80端口被占用6. java - SSH框架中寫分頁時(shí)service層中不能注入分頁類7. docker安裝后出現(xiàn)Cannot connect to the Docker daemon.8. dockerfile - 為什么docker容器啟動(dòng)不了?9. golang - 用IDE看docker源碼時(shí)的小問題10. docker api 開發(fā)的端口怎么獲取?

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