Select2-使用总结

 1、Select2-下拉框去除已经选中的值

解决方法如下:通过设置css样式来使已选择的选项不显示

.select2-results__option[aria-selected=true]{
        display:none;
}

 

2、 Select2-多选,后端取值

Enumeration<String> paraNames = request.getParameterNames();
String paraName = null;
while (paraNames.hasMoreElements()) {
	paraName = (String) paraNames.nextElement();
	if (paraName.indexOf("depends") == 0) {
		String[] protaskIds = request.getParameterValues(paraName);
		String protaskId = null;
		for (int i = 0; i < protaskIds.length; i++) {
			protaskId = protaskId + "," + protaskIds[i] ;
		}
		protaskId = protaskId.substring(5, protaskId.length());
		addProtask.setDepends(protaskId);
	}
}

通过 request.getParameterValues(paraName) 可以获得前端select2选中值的id

 

3、Select2-动态回显值

<select class="form-control select2" multiple="multiple" id="depends" name="depends" style="width: 100%;" >
	<option selected=true  th:each="c:${depends}"  th:value="${c.id}" th:text="${c.name}"></option>
</select>

通过model传递对象,前端遍历对象即可。重点:select2需要通过value,查到对应的text。

设置默认值:https://blog.csdn.net/shu580231/article/details/76218942

 

相关问题总结链接:https://www.cnblogs.com/richard-wzh/p/6796412.html

©️2020 CSDN 皮肤主题: 像素格子 设计师:CSDN官方博客 返回首页