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. js精确加减乘除

    //加法函数function accAdd(arg1, arg2) { var r1, r2, m; try { r1 = arg1.toString().split(".")[1 ...

  2. cosbench 异常 FreeMarker template error: The following has evaluated to null or missing

    问题现象: 使用Cosbench 0.4.2.c4 版本测试Ceph RGW read test失败,遇到异常如下: FreeMarker template error: The following ...

  3. Flyme适配源码更新命令,轻松完成打包

    第一次已经同步了所有源码(花了很长时间),第一次已经连接手机进行了插桩和解reject,那么第二次还需要这么麻烦吗?答案是:NO ! 1.官方源码,执行如下命令可以实现: repo sync -c 2 ...

  4. 移植eac3音频库

    2016-5-26 移植eac3音频库,从ffmpeg库中移植.经过验证是切实可行的. 感觉开源软件就是时间黑洞,有多少时间搭进去都不为过.已经3周过去了,ffmpeg还是没有熟悉完. 真正的移植工作 ...

  5. VS2015链接错误一则

    以前天真的以为C是C++的子集,.c文件直接.cpp命名没什么影响: 后缀一改 链接器工具错误 LNK2019

  6. Python中的file和open简述

    help(file) help(open) 老规矩先看一下内置的帮助文档怎么描述file和open,毕竟官方文档是最直接最准确的描述. Help on class file in module __b ...

  7. Google map markers

    现已被屏蔽 http://mabp.kiev.ua/2010/01/12/google-map-markers/ Надо по немногу отходить от празднывания но ...

  8. (转)MySQL索引原理及慢查询优化

    转自美团技术博客,原文地址:http://tech.meituan.com/mysql-index.html 建索引的一些原则: 1.最左前缀匹配原则,非常重要的原则,mysql会一直向右匹配直到遇到 ...

  9. js中的逻辑与(&&)和逻辑或(||)

    之前有一个同事去面试,面试过程中碰到这样一个问题: 在js中写出如下的答案 : var a = 2; var b = 3; var andflag = a && b ; var orf ...

  10. PHP中判断变量为空的几种方法

    判断变量为空,在许多场合都会用到,同时自己和许多新手一样也经常会犯一些错误, 所以自己整理了一下PHP中一些常用的.判断变量为空的方法. 1. isset功能:判断变量是否被初始化本函数用来测试变量是 ...