angular.js - 關(guān)于ng-option的用法
問(wèn)題描述
數(shù)據(jù)是這樣的
那我如果用ng-option怎么循環(huán)出來(lái)這些數(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ù)的值
問(wèn)題解答
回答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];//通過(guò)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. mysql - 分庫(kù)分表、分區(qū)、讀寫(xiě)分離 這些都是用在什么場(chǎng)景下 ,會(huì)帶來(lái)哪些效率或者其他方面的好處2. javascript - ios返回不執(zhí)行js怎么解決?3. python - 爬蟲(chóng)模擬登錄后,爬取csdn后臺(tái)文章列表遇到的問(wèn)題4. 視頻文件不能播放,怎么辦?5. python bottle跑起來(lái)以后,定時(shí)執(zhí)行的任務(wù)為什么每次都重復(fù)(多)執(zhí)行一次?6. html5 - HTML代碼中的文字亂碼是怎么回事?7. javascript - 求幫助 , ATOM不顯示界面!!!!8. mysql 查詢(xún)身份證號(hào)字段值有效的數(shù)據(jù)9. javascript - angular使從elastichearch中取出的文本高亮顯示,如圖所示10. javascript - 為什么在谷歌控制臺(tái) 輸出1的時(shí)候,輸出的1立馬就不見(jiàn)了
