select2的使用步骤

select2相关文件链接:

https://pan.baidu.com/s/1WemkNAsKkcY4Ozf1lwGqAw
提取码:p752

1.后端

   1.1dao层 : 在xxxmapper.xml文件中添加

  <select id="selectOptionList"  resultType="java.util.Map" >

    select id,name as text from tb_brand

  </select>

        在xxxMapper.java中编写接口文件

 List<Map> selectOptionList();

   1.2 接口层添加方法

    List<Map> selectOptionList();

      接口实现

      public List<Map> selectOptionList() {

             return brandMapper.selectOptionList();

       }

     1.3controller层

@RequestMapping("/selectOptionList")

public List<Map> selectOptionList(){

return brandService.selectOptionList();

}

2.前端

   2.1service层

app.service('brandService',function ($http) {
  this.selectOptionList = function () {
    return $http.get('../brand/selectOptionList.do') ;
});

   2.2controller层

 //控制层 
app.controller('typeTemplateController' ,function($scope,$controller   ,typeTemplateService,brandService,specificationService){     //引入service层服务brandService
//定义品牌列表数据
$scope.brandList = {data : []} ;
   //查询品牌列表
   $scope.findBrandList = function () {
       brandService.selectOptionList().success(
           function (response) {
               $scope.brandList = {data : response};
           }
       );
   }

});

   2.3页面引入样式文件

<link rel="stylesheet" href="../plugins/select2/select2.css" />
<link rel="stylesheet" href="../plugins/select2/select2-bootstrap.css" />
<script src="../plugins/select2/select2.min.js" type="text/javascript"></script>

   2.4页面引入select2的库文件

<!--引入angular-select2.js 必须放在app模块下,因为此js文件依赖于app模块-->
<script type="text/javascript" src="../js/angular-select2.js">  </script>

   2.5在页面中引入相应的service服务层

<script type="text/javascript" src="../js/service/brandService.js">  </script>

特别注意一下,JS引入的位置,要在typeTemplateController.js之前,因为该控制器要使用到它

   2.6修改type_template.html ,添加初始化

<body class="hold-transition skin-red sidebar-mini" ng-app="pinyougou" ng-controller="typeTemplateController" ng-init="findBrandList()">

   2.7select2 下拉框

<!--config:用于配置数据来源   select2-model:用于指定用户选择后提交的变量   multiple:表示多选-->
<input select2 config="brandList" select2-model="entity.brandIds" multiple placeholder="选择品牌(可多选)" class="form-control" type="text" >

2.8清除新建按钮缓存

ng-click="entity={}"

 

 

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值