`
Franciswmf
  • 浏览: 797146 次
  • 性别: Icon_minigender_1
  • 来自: 上海
文章分类
社区版块
存档分类
最新评论

angularjs select multiple="multiple" ng-repeat

 
阅读更多
效果图:



<!DOCTYPE html>
<html ng-app="app">
<head>
<meta charset="utf-8">
<script src="editor-app/libs/angular_1.2.13/angular.min.js"></script>
<script src="editor-app/libs/angular_1.2.13/angular-animate.min.js"></script>
<link rel="stylesheet" href="editor-app/css/style-common.css">
<script type="text/javascript">
	angular.module('app', [])
	.controller('MyCtrl', ['$scope','myCache',function($scope,myCache){
		$scope.multiSelectList=[
		                        {id:1,name:'red',group:'china',selected:false},
		                        {id:2,name:'yellow',group:'china',selected:false},
		                        {id:3,name:'grey',group:'china',selected:false},
		                        {id:4,name:'pink',group:'china',selected:false},
		                        {id:5,name:'purple',group:'china',selected:false}
		                        ];
		/*默认选中:default selected*/
		var arr=["2","3","5"];
		angular.forEach(arr,function(val,idx){
			var keep=true;
			angular.forEach($scope.multiSelectList,function(value,index){
				if(keep){
					if(value.id==val){
						value.selected=true;
						keep=false;
					}
				}
			})
		});
		myCache.put("selected",arr);
		$scope.myMultiSelectModel=myCache.get("selected");
		/*单项点击事件:item click*/
		$scope.itemClickFun=function(x){
			var obj=myCache.get("selected");
			if(x.selected){
				x.selected=false;
				var nObj=[];
				angular.forEach(obj,function(val,idx){
					if(val!=x.id){
						nObj.push(val.toString());
					}
				});
				myCache.put("selected",nObj);
			}else{
				x.selected=true;
				
				if(""==obj||null==obj){
					obj.push(x.id.toString());
				}else{
					var bFlag=true;
					angular.forEach(obj,function(val,idx){
						if(bFlag){
						obj.push(x.id.toString());
						bFlag=false;
						}
					});
				}
				myCache.put("selected",obj);
			}
			$scope.myMultiSelectModel=myCache.get("selected");
		}

	}]);
	angular.module('app').factory('myCache', function($cacheFactory) {
		 return $cacheFactory('myData');
	});
</script>
</head>
<!-- body #s -->
<body ng-controller="MyCtrl">
 <select id="stId" multiple="multiple" ng-model="myMultiSelectModel" size="8" aria-describedby="basic-addon2">
     <option ng-repeat="multi in multiSelectList" value='{{multi.id}}'  ng-selected="{{multi.selected}}"  ng-click="itemClickFun(multi)">{{multi.name}}</option>
</select>
<br>
<h4>多选select选中项={{myMultiSelectModel}}</h4>
</body>
<!-- body #e -->
</html>
  • 大小: 4.3 KB
分享到:
评论

相关推荐

    angularjs ui-select2 多选下拉所需资源文件

    &lt;select multiple ng-model="selectedItems" ui-select2&gt; &lt;option ng-repeat="item in items" value="{{item.id}}"&gt;{{item.name}} &lt;/select&gt; ``` 在这里,`items`是一个包含所有可选项的对象数组,`...

    AngularJS ng-table插件设置排序

    2. **模板(Template)**:ng-table支持多种类型的值模板,包括`number`(数字)、`text`(文本)、`select`(单选)和`select-multiple`(多选)。这些模板可以根据需要自定义列的显示和交互方式。 3. **初始过滤...

    ng-select-text

    "ng-select-text" 是一个基于 AngularJS 的插件,它为 Web 应用程序提供了可定制的下拉选择框功能。这个插件的设计受到了 StackOverflow 的启发,旨在提供一种高效、用户友好的方式来处理多选和单选的下拉选项。在...

    ng-sumoselect

    ng-sumoselect的角度包装该指令可将... 将指令添加到视图中的任何选择元素 select ( sumoselect = '{placeholder:"Select Me", search:true}' , multiple = 'true' , ng-model = 'selected' ) option ( ng-repeat

    AngularJS实现动态添加Option的方法

    在本文中,我们了解了如何创建AngularJS应用,定义控制器,以及如何使用`ng-repeat`、`ng-model`和`ng-click`等指令来实现动态添加Option的功能。同时,我们还学习了如何检查Option的唯一性以防止重复添加。通过这些...

    angular写一个列表的选择全选交互组件的示例

    &lt;tr ng-repeat="item in list" mo-select-single&gt; &lt;td&gt;&lt;input type="checkbox" ng-checked="item.select" mo-select-single1&gt; &lt;!-- 其他列 --&gt; ``` **参数说明** - `mo-select`:列表对象,与`ng-repeat`...

    Angular实现下拉框模糊查询功能示例

    &lt;select ng-change="change(x)" ng-model="x" multiple&gt; &lt;option ng-repeat="data in datas"&gt;{{data}} &lt;/select&gt; ``` `ng-model`绑定的`x`变量会在选择项时更新,而`ng-change`会调用`change`方法将选择的值同步到...

    Angularjs单选改为多选的开发过程及问题解析

    在JavaScript中,开发者通过一个数组$scope.productTypes来存储产品类型的信息,并通过ng-repeat指令动态生成每个选项。用户可以使用md-select来选择多种产品类型,同时通过按钮来重置选择。 在遇到问题时,开发者...

    dropdownlist下拉框实现多选

    &lt;select id="myDropdown" multiple&gt; &lt;option value="option1"&gt;Option 1 &lt;option value="option2"&gt;Option 2 &lt;option value="option3"&gt;Option 3 &lt;!-- 更多选项... --&gt; &lt;/select&gt; ``` 在这个例子中,用户可以同时...

    Bochs - The cross platform IA-32 (x86) emulator

    - multiple sector read/write support for some image modes - new log prefix "IMG" for hdimage messages - floppy - added write protect option for floppy drives (based on @SF patch by Ben Lunt) - ...

    net架构练习题

    `multiple`:正确答案,使用`multiple`属性可以让`&lt;select&gt;`元素支持多选。 - B. `size`:用来设置下拉列表的高度。 - C. `selected`:用来设置某个`&lt;option&gt;`被选中。 - D. `checked`:这不是一个有效的HTML...

    FastReport.v4.15 for.Delphi.BCB.Full.Source企业版含ClientServer中文修正版支持D4-XE5

    - improved crosstab speed when using repeat band with crosstab object version 4.9 --------------- + added outline to PDF export + added anchors to PDF export - fixed bug with embedded TTC fonts in ...

    BURNINTEST--硬件检测工具

    - Minor change to the 2D memory test when run with the 3D test (multiple large windows) and the RAM test. Aimed at correcting sympton: Access Violation 0x00404CF9. - Corrections to the mapping of ...

    RxLib控件包内含RxGIF,全部源码及DEMO

    select multiple records; convert columns headings to buttons. TDBStatusLabel displays the DataSet state (for all datasets) or current record number (for DBase or Paradox tables). TDateEdit and ...

    advanced web server -Rompager

    - **固定列表(多选) `&lt;select multiple&gt;&lt;option&gt;`**:允许用户从下拉列表中选择多个选项。 - **可变列表(字符串值) `&lt;select&gt;&lt;option&gt;`**:根据后端提供的数据动态生成选项列表。 - **可变列表(项目编号) `...

    Senfore_DragDrop_v4.1

    Just open the forms in the IDE, then select "Ignore All" when the IDE complains that this or that property doesn't exist and finally save the forms. ------------------------------------------- 3. ...

    Fuzzy and Neuro-Fuzzy Systems in Medicine

    4.2 Evaluation Over Repeat Scans 5. Discussion References Abbreviations Part 2—Neuro-Fuzzy Knowledge Processing Chapter 6—An Identification of Handling Uncertainties Within Medical ...

    WCDMA 缩略语.txt

    **WCDMA(Wideband Code Division Multiple Access)**是一种3G移动通信标准,广泛应用于全球各地。它通过利用码分多址技术来提供宽带通信服务。 #### 2G - 第二代移动通信系统 **2G(2nd Generation Mobile ...

    BUS Hound

    The repeat count feature can be turned off by deselecting the “Merge Repeated Commands” check box in the settings Window. &lt;br&gt;Date &lt;br&gt;Date the phase occurred in year/month/day format. &lt;br...

Global site tag (gtag.js) - Google Analytics