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 ...
随机推荐
- myeclipse 注释模板
选中你要加注释的方法或类,按 Alt + shift + J.
- 使用VS Code 从零开始开发并调试.NET Core 应用程序
最新文章:http://www.cnblogs.com/linezero/p/VSCodeNETCore.html 使用VS Code 从零开始开发并调试.NET Core 应用程序,C#调试. 上一 ...
- JAVA 技术手册 卷1 第十四章『多线程』 读书摘要
什么是线程 进程受CPU时间片的轮转调度,进而予人多任务并发的感觉. 线程在更低层次上扩展多任务概念,一个进程通常包含多个线程. 进程各自数据独立,而线程共享数据. 数据独立使进程相互通信变得繁难,共 ...
- 学习笔记——git
恩没错,又是个新东西 使用Git提交文件到版本库有两步: 第一步:是使用 git add 把文件添加进去,实际上就是把文件添加到暂存区. 第二步:使用git commit提交更改,实际上就是把暂存区的 ...
- 查找树ADT——二叉搜索树
在以下讨论中,虽然任意复杂的关键字都是允许的,但为了简单起见,假设它们都是整数,并且所有的关键字是互异的. 总概 使二叉树成为二叉查找树的性质是,对于树中的每个节点X,它的左子树中所有关键字值小于 ...
- asp.net 的页面几种传值方式
http://www.cnblogs.com/makqiq/p/5882448.html 1.Querystring Querystring也叫查询字符串,这种页面间传递数据是利用网页地址URL.如果 ...
- 网页特效:用CSS3制作3D图片立方体旋转特效
<!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <title&g ...
- eclipse安装Eclipse Memory Analyzer插件
在Install New software中输入 http://archive.eclipse.org/mat/1.2/update-site/ 然后选择Memory Analyzer for Ecl ...
- 《大型网站系统与Java中间件实践》读书笔记——CAP理论
分布式事务希望在多机环境下可以像单机系统那样做到强一致,这需要付出比较大的代价.而在有些场景下,接收状态并不用时刻保持一致,只要最终一致就行. CAP理论是Eric Brewer在2000年7月份的P ...
- [UML]UML系列——用例图Use Case
用例图的概念 用例图是描述用例.参与者以及它们之间关系的图. 用例图的作用 用例图是从用户的角度来描述对信息系统的需求,分析产品的功能和行为. 用例图定义和描述了系统的外部可见行为,是分析.设计直至组 ...