i'm trying to display a hashmap keyset in a bootstrap table, but only the first character is showing.
This is my rest service function:
@GET
@Path("getquizes")
@Produces(MediaType.APPLICATION_JSON)
public Collection<String> getQuizes() {
System.out.println(activeQuizes.keySet());
return activeQuizes.keySet();
}
It is working. This is what i am receive:
Here is my Html:
<table data-toggle="table" id="tablequizes" class="display table table-bordered">
<thead>
<tr>
<th datatype="String">Name</th>
</tr>
</thead>
</table>
And my javascript:
function fetchQuizes() {
$.ajax({
url: 'rest/Quiz/getquizes',
type: 'GET',
datatype: 'json',
success: function (data) {
console.info(data);
$('#tablequizes').bootstrapTable('load', data);
},
error: function (result) {
console.info(result.responseText);
}
});
}
But the result is only showing the first character in the array:
I think you are getting wrong about what the keySet()
is giving you:
Returns a Set view of the keys contained in this map.
You are getting only the key and not the value of the map. For getting the value use values()
Returns a Collection view of the values contained in this map
activeQuizes.values(); //Try with this.
You can try changing your ajax output content tablequizes to an Array with some name id in it in your JS.
Eg: [ {"name": "Quiz1"}, {"name": "Quiz2"} ]
And modify the th tag
<th data-field="name">Name</th>
This should solve your problem.
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.