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. macos - 無(wú)法source activate python272. javascript - 微信網(wǎng)頁(yè)開(kāi)發(fā)從菜單進(jìn)入頁(yè)面后,按返回鍵沒(méi)有關(guān)閉瀏覽器而是刷新當(dāng)前頁(yè)面,求解決?3. 預(yù)訂金和尾款分別支付4. javascript - h5微信中怎么禁止橫屏5. empty比isset更嚴(yán)格一點(diǎn)6. 運(yùn)行python程序時(shí)出現(xiàn)“應(yīng)用程序發(fā)生異?!钡膬?nèi)存錯(cuò)誤?7. 我在導(dǎo)入模板資源時(shí)遇到無(wú)法顯示的問(wèn)題,請(qǐng)老師解答下8. PHPExcel表格導(dǎo)入數(shù)據(jù)庫(kù)怎么導(dǎo)入9. thinkphp6使用驗(yàn)證器 信息如何輸出到前端頁(yè)面10. python - sqlalchemy更新數(shù)據(jù)報(bào)錯(cuò)

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