AngularJS进阶 五 Angular实现下拉菜单多选

本文介绍了如何使用 AngularJS Dropdown Multiselect 模块来创建具有多选功能的下拉菜单。该指令基于 Bootstrap,不需要 jQuery,并提供搜索、预选值、限制选择数量等特性。详细用法包括在 HTML 中引入依赖库、添加模块依赖以及在控制器中设置选项和选中模型。同时,文中提供了代码示例和实际效果截图。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

               

Angular实现下拉菜单多选

写这篇文章时,引用文章地址如下:

http://ngmodules.org/modules/angularjs-dropdown-multiselect

http://dotansimha.github.io/angularjs-dropdown-multiselect/#/

AngularJS Dropdown Multiselect

This directive gives you a Bootstrap Dropdown with the power of AngularJS directives.

Features

Based on Bootstrap's dropdown.

jQuery is not necessary.

Seperated your data and the selection data. no modification to the data made.

Built-in search.

Complete control on the selected items model to fit it to your requirements.

Two view options: normal list and checkboxes.

Pre-selected values.

Limit selection count.

Grouping items by property.

Callback events.

Demo

http://dotansimha.github.io/angularjs-dropdown-multiselect/

Dependencies

required: AngularJS >= 1.2, Lodash >= 2, Bootstrap >= 3.0

Make sure to add the dependencies before the directive's js file.

Note: Bootstrap JS file is not needed for the directive, it just uses the CSS file.

Install

Download the files

Using bower:

Just run bower install angularjs-dropdown-multiselect

Manually: You can download the .js file directly or clone this repository.

Include the file in your app

<script type="text/javascript" src="angularjs-dropdown-multiselect.js"></script>.

You can also use the minfined version (angularjs-dropdown-multiselect.min.js).

Include the module in angular (i.e. in app.js) - angularjs-dropdown-multiselect

Usage and Documentation

See the documentation and examples in the GitHub pages: http://dotansimha.github.io/angularjs-dropdown-multiselect/

由以上英文文档可以得知,若使用angularjs-dropdown-multiselect,首先需要在index.html中引入AngularJS >= 1.2, Lodash >= 2, Bootstrap >= 3.0,如下所示:

<script src="js/angularjs-dropdown-multiselect.js"></script>

<script src="js/lodash.min.js"></script>

并在app.js模块中添加依赖angularjs-dropdown-multiselect。如下所示:

var routerApp = angular.module('routerApp', ['ui.router', 'ngCookies', 'ngTable', 'angularjs-dropdown-multiselect', 'MedListModule']);

yh_set_dtl.html核心代码如下:

<div style="float:left">优 惠 类 型:</div>

<!-- Demo -->

<div ng-dropdown-multiselect="" 

 options="yhctlModelOptions" 

 selected-model="yhctlModel"

 checkboxes="true">

</div>

controllers.js代码如下:

 $scope.yhctlModel = [];

 

 $scope.yhctlModelOptions = [ 

                              {id: 1, label: '限定用户'}, 

                              {id: 2, label: "限定商家"}, 

                              {id: 3, label: "限定使用次数"},

                              {id: 4, label: "限定药品"}, 

                              {id: 5, label: "与其它优惠共享"}];

效果图如下:

 

           

再分享一下我老师大神的人工智能教程吧。零基础!通俗易懂!风趣幽默!还带黄段子!希望你也加入到我们人工智能的队伍中来!https://blog.youkuaiyun.com/jiangjunshow

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值