angularjs---select使用---默认值及联动

 

代码

一. select设置默认显示内容&&获取下拉框显示内容.

HTML

<div>
  <select ng-model="current_option" ng-options="option.key for option in option_array"> </select>
</div> JS $(function()
{
/**** 设置下拉框显示内容 ****/
$scope.option_array = [
{"key" : "hello", "value" : 1},
{"key" : "world", "value" : 2},
];
$scope.current_option = $scope.option_array[0]; // 下拉框默认显示内容 console.log($scope.current_option.key); // 获取下拉框显示内容
console.log($scope.current_option.value); // 获取下拉框显示内容对应的值
}) 二. select二级联动.
HTML <div>
  <select ng-model="current_option" ng-options="option.key for option in option_array" ng-change="current_option_change()"> </select>
</div>
<div>
  <select ng-model="child_current_option" ng-options="option.key for option in child_option_array"> </select>
</div> JS $(function() // 这是动作, 立即执行
{
/**** 设置父下拉框显示内容 ****/
$scope.option_array = [
{"key" : "hello", "value" : 2},
{"key" : "world", "value" : 2},
];
$scope.current_option = $scope.option_array[0]; // 父下拉框默认显示内容 /**** 初始加载时根据父下拉框内容显示子下拉框内容 ****/
$scope.child_change_with_father();
}) /**** 根据父下拉框当前显示内容设置子下拉框内容 ****/
$scope.child_change_with_father = function () // 这是方法, 调用执行
{
if ("hello" == $scope.current_option.key)
{
$scope.child_option_array = [
{"key" : "hello_child_one", "value" : 1},
{"key" : "hello_child_two", "value" : 2},
];
}
else if ("world" == $scope.current_option.key)
{
$scope.child_option_array = [
{"key" : "world_child_one", "value" : 3},
{"key" : "world_child_two", "value" : 4},
];
}
$scope.child_current_option = $scope.child_option_array[0]; // 子下拉框默认显示内容
} $scope.current_option_change = function()
{
$scope.child_change_with_father();
}

angularjs---select使用---默认值及联动的更多相关文章

  1. AngularJS的select设置默认值

    AngularJS的select设置默认值 在使用Angular时候使用select标签时会遇到绑定数据指定默认显示值可这样实现 <!DOCTYPE html> <html ng-a ...

  2. element UI select 设定默认值

    要为select设定默认值,有两个步骤 1.数据中,声明一个变量param:该变量的值设为你想设定的select option中value 2.控件的 v-model 绑定 param 即可 < ...

  3. angularjs中下拉框select option默认值

    1.问题说明: option ng-repeat多空白项 2.解决方案: html: <ion-view hide-nav-bar="true"> <ion-co ...

  4. jquery 设置select的默认值

    <select id="sel" > <option value="s1" > aaaa </option> <opt ...

  5. angularJs select ng-selected默认选中遇到的坑

    本人,程序员妹子一枚,,,,名字中有萌字,简称萌妹子哈,,,首先贴出代码: 同样的方式,用ng-selected用来做回显,但是结果让萌妹我很是诧异,第一个“模板类型”那里的select可正常回显,第 ...

  6. <select>标签默认值设置

    <td> <label>操作类型:</label> <select id="operation_type" class="com ...

  7. 给iview组件select设置默认值

    1.首先,给select加一个v-model,如: <Select v-model="exam_name" > <Option v-for="(item ...

  8. layui select恢复默认值

  9. 设置select默认值

    W3C下设置一个默认值直接为 select.value='默认值'. IE8下设置默认值必须有这个option才能被设置,不像W3C 如chrome这种,直接设置就能显示,如果IE下这样设置的话sel ...

随机推荐

  1. iOS对键盘的处理

    方法1. 使用<UITextFeildDelegate>,使用的UITextField示例 设置其Delegate为self,点击return按钮隐藏键盘.实现函数如下:    - (BO ...

  2. JBPM4.4业务流程管理框架详细解读

    1. 什么是JBPM4.4业务流程管理框架? JBPM,全称是JavaBusiness Process Management(业务流程管理),它是覆盖了业务流程管理.工作流.服务协作等领域的一个开源的 ...

  3. console.log((function f(n){return ((n > 1) ? n * f(n-1) : n)})(5))调用解析

    console.log((function f(n){) ? n * f(n-) : n)})()); 5被传入到函数,函数内部三元计算,5 > 1成立,运算结果是5*f(4),二次运算,5*4 ...

  4. Android进程整理

    一.概括 系统启动架构图: 上图在Android系统-开篇中有讲解,是从Android系统启动的角度来分析,本文是从进程/线程的视角来分析该问题. 1.1 父进程 在所有进程中,以父进程的姿态存在的进 ...

  5. Leetcode 94. Binary Tree Inorder Traversal

    Given a binary tree, return the inorder traversal of its nodes' values. For example:Given binary tre ...

  6. Jquery动态添加的元素绑定事件的3种方法

    假设我们点击li标签,弹出他的文本,如果是动态添加的li,点击是没有效果的,压根弹不出来文本. 下面博主分享一下为动态添加的元素绑定事件的三种方法,网上一般都是两种,我在这里多增加了一种. 事件案例: ...

  7. 11月7日下午PHP----PDO访问方式操作数据库

    MySQLI是专门访问MySQL数据库的,不能访问其它数据库.PDO可以访问多种的数据库,它把操作类合并在一起,做成一个数据访问抽象层,这个抽象层就是PDO,根据类操作对应的数据库.mysqli是一个 ...

  8. 转-ArcGIS Engine许可初始化

    关于初始化Engine许可的,其实原理都很简单,大家一般都没有问题,但又往往会因为不够细心加上Engine的“小脾气”,让不少程序员都要在这里犯错. 以Engine9.2为例,应用程序是强制初始化许可 ...

  9. MySQL 5.6 新参数对binlog日志量的优化

    数据库版本:5.6.* 1.row日志image类型 参数binlog_row_image 控制着这种image类型,默认为FULL(log all columns),即记录before&af ...

  10. Redis总结(四)Redis 的持久化

    前面已经总结了Redis 的安装和使用今天讲下Redis 的持久化. redis跟memcached类似,都是内存数据库,不过redis支持数据持久化,也就是说redis可以将内存中的数据同步到磁盘来 ...