angular.js - 关于ng-option的用法

查看:85
本文介绍了angular.js - 关于ng-option的用法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问 题

数据是这样的

那我如果用ng-option怎么循环出来这些数据

现在代码是这样的:

<div class="am-form-group">
            <label class="am-u-sm-3 am-u-md-3 am-u-lg-2 am-form-label am-text-right">导演国籍:</label>
            <div class="am-u-sm-9 am-u-md-9 am-u-lg-10">
                <select id="direct-country" class="am-radius max-width-250" 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>
            </div>
        </div>

控制器:

$scope.countrys_1 = data.nationality;
$scope.selected_cn_1 = data.nationality[46];

我想让option的value是 下标,不知道怎么改,默认显示为第46条数据的值

解决方案

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的用法

这篇关于angular.js - 关于ng-option的用法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆