[英]How to display Java Hashmap.keySet() in a bootstrap table, from a java rest service?
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:
这就是我收到的:
Received Json object 收到的Json对象
Here is my Html: 这是我的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: 而我的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: 但是结果仅显示数组中的第一个字符:
Bootstrap datatable with hashmap keyset 具有哈希映射键集的Bootstrap数据表
I think you are getting wrong about what the keySet()
is giving you: 我认为您对
keySet()
给您的内容有误:
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()
要获取值,请使用
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. 您可以尝试在JS中将ajax输出内容表查询更改为带有名称ID的数组。
Eg: [ {"name": "Quiz1"}, {"name": "Quiz2"} ]
And modify the th tag 并修改th标签
<th data-field="name">Name</th>
This should solve your problem. 这应该可以解决您的问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.