<%
UsrealmManager manager = new UsrealmManager();
List<Usrealm> realmList = manager.realmlist();
%>
<select name="Realms">
<%for (Usrealm usrealm : realmList) {%>
<option value="<%=usrealm.getUsrealmId()%>"><%=usrealm.getRealmName()%>
</option>
<%}%>
</select>
I have a list of objects in JSP and filling the select tag with them. I need to write an autocomple with Jquery but I cant use realmList on the javascript side. What should I do? I couldnt parse Java Object List to Json.
You can use autocomplete widget from jquery UI ( https://jqueryui.com/autocomplete/ ). With this plugin you can create a javascript array from java pojos and pass it to the autocomplete method.
Using the example on jquery UI sites:
<%
UsrealmManager manager = new UsrealmManager();
List<Usrealm> realmList = manager.realmlist();
%>
<script>
$(function() {
var availableTags = [
<%for (Usrealm usrealm : realmList) {%>
{ label: '<%=usrealm.getRealmName()%>', value: '<%=usrealm.getUsrealmId()%>' }
<%}%>
];
$( "#tags" ).autocomplete({
source: availableTags
});
</script>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.