200字范文,内容丰富有趣,生活中的好帮手!
200字范文 > 使用angularjs完成可多选下拉列表功能:select2

使用angularjs完成可多选下拉列表功能:select2

时间:2021-11-03 00:49:01

相关推荐

使用angularjs完成可多选下拉列表功能:select2

tb_type_template 模板表字段类型长度含义IdBigint主键nameVarchar80模板名称Spec_idsVarchar1000关联规格(json格式)brand_idsVarchar1000关联品牌(json格式)custom_attribute_itemsVarchar2000扩展属性

前端:

select2组件在官网下载!

HTML:

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

js:

$scope.brandList={data:[]};//此为数据来源,创建关联品牌对象,对象中的对象为品牌数据$scope.findBrandList=function(){$http.get(url).success(function(response){$scope.brandList={data:response};});}

后端:因为select2的config数据来源固定格式为[{id:2,text:联想},…]

所以后端需要查询id与name并返回修改属性名字后的json数据,所以

DAO:

xml:

select id,nameas text

from tb_brand

dao:

ListselectOptionList();

Service:

ListselectOptionList();

public List<Map> selectOptionList() {return brandMapper.selectOptionList();

}

Controller:

@RequestMapping("/selectOptionList")

public ListselectOptionList(){

return brandService.selectOptionList();

}

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。