我正在使用這個website的jquery腳本。使用spring MVC添加動態數據到可搜索的多選jquery MVC
控制器春:
@RequestMapping(value="/method2/submit",method = RequestMethod.POST)
public String method3(ModelMap model, @ModelAttribute("data") Data data) {
model.addAttribute("data",new Data());
ArrayList<String> array = new ArrayList<String>();
array.add("Variable 1-Definition 1");
array.add("variable 2 - Definition 2");
array.add("variable 3-Definition 3");
model.addAttribute("variableList", array);
System.out.print(array);
return VIEWS_LOCATION +"/secondPage";
}
- JSP頁面:
<script>
var abc = $('.demo').dropdown({
\t multipleMode : 'label',
\t
});
console.log("doc load"+abc);
</script>
<div class="demo" id="dropdown1">
<form:select style="display: none" name="" id="values" path="name" multiple="true">
\t <form:option value="variable11" selected="true">variable1</form:option>
\t <form:option value="variable2" >variable2</form:option>
\t <form:option value="variable3" >variable3</form:option>
\t <form:options items="${variableList}" /> \t \t \t
</form:select>
</div>
動態數據可以包含高達500個條目將被從文件中讀取。添加3個變量僅用於表示目的。請幫助我將動態數據添加到下拉列表中。謝謝!
參考解決方案以及https://www.mkyong.com/spring-mvc/spring-mvc-dropdown-box-example/ –