angularjs---select使用---默认值及联动
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使用---默认值及联动的更多相关文章
- AngularJS的select设置默认值
AngularJS的select设置默认值 在使用Angular时候使用select标签时会遇到绑定数据指定默认显示值可这样实现 <!DOCTYPE html> <html ng-a ...
- element UI select 设定默认值
要为select设定默认值,有两个步骤 1.数据中,声明一个变量param:该变量的值设为你想设定的select option中value 2.控件的 v-model 绑定 param 即可 < ...
- angularjs中下拉框select option默认值
1.问题说明: option ng-repeat多空白项 2.解决方案: html: <ion-view hide-nav-bar="true"> <ion-co ...
- jquery 设置select的默认值
<select id="sel" > <option value="s1" > aaaa </option> <opt ...
- angularJs select ng-selected默认选中遇到的坑
本人,程序员妹子一枚,,,,名字中有萌字,简称萌妹子哈,,,首先贴出代码: 同样的方式,用ng-selected用来做回显,但是结果让萌妹我很是诧异,第一个“模板类型”那里的select可正常回显,第 ...
- <select>标签默认值设置
<td> <label>操作类型:</label> <select id="operation_type" class="com ...
- 给iview组件select设置默认值
1.首先,给select加一个v-model,如: <Select v-model="exam_name" > <Option v-for="(item ...
- layui select恢复默认值
- 设置select默认值
W3C下设置一个默认值直接为 select.value='默认值'. IE8下设置默认值必须有这个option才能被设置,不像W3C 如chrome这种,直接设置就能显示,如果IE下这样设置的话sel ...
随机推荐
- 基于Xenomai的实时Linux分析与研究
转自:http://blog.csdn.net/cyberlabs/article/details/6967192 引 言 随着嵌入式设备的快速发展,嵌入式设备的功能和灵活性要求越来越高,很多嵌入式设 ...
- 【jQuery示例】遍历表单数据并显示
<!DOCTYPE html> <html> <head> <style> body, select { font-size:14px; } form ...
- itertools
0. Python中引入itertools 1. 笛卡尔积: product(iter1, iter2,...,iterN,[repeat=i]) from itertools import prod ...
- 线段树 poj 3667
1-n线段 m个操作 1 a 是否可找到连续a个空位子 有输出最左边(然后使这一段被占)没有0 2 a ,b a~b区间变成未使用 #include<stdio.h> #include& ...
- 前端构建工具:gulp的配置与使用
安装gulp 因为gulp是基于node的管理工具,所以要先安装nodejs安装nodejsnodejs下载地址:中文站:http://nodejs.cn/ 英文站:https://nodejs.or ...
- 浅谈CSRF攻击方式
一.CSRF是什么? CSRF(Cross-site request forgery),中文名称:跨站请求伪造,也被称为:one click attack/session riding,缩写为:CSR ...
- python2-gst0.10制作静态包的补丁
gst制作成了静态库,而python2的gst有多个动态库引用gst的库 因此,想了一个办法将python2所需要的gst打包成一个单独的共享库 办法就是,将python2_gst所有的.so先制作成 ...
- Java创建对象的几种方法
有时候,也可能碰到这样面试题,如: Java创建对象有哪几种方法? 除了new之外,java创建对象还有哪几种方式? 本文结合例子,给出几种Java创建对象的方法,Here we go~~~~ 使用n ...
- PHP 图片上传
PHP上传的简单案例: Html文件: <html> <form action="index.php" name="form" method= ...
- 关于jquery 集合对象的 each和click方法的 思考 -$(this)的认识
1, 很重要的是: each: 是 自动遍历 集合中所有 item的, 是自动的; click: 包括其他所有的 "事件", 如mouseX事件, keyX事件等, 都不是 自动 ...