简体   繁体   English

如何从Java Rest服务在引导表中显示Java Hashmap.keySet()?

[英]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.

相关问题 如何从Java的REST服务返回对象? - How to return object from rest service in java? 如何从Java Rest Web服务返回ajax中的值? - How to return a value in ajax from a Java Rest Web service? 如何从 html 获取文本字段值并将其传递给 REST GET 服务并在动态 HTML 表中显示响应 - How to get text field value from html and pass it to REST GET service and display the response in dynamic HTML table 带有 Java (REST) 的 AngularJS 服务? - AngularJS service with Java (REST)? 如何将哈希图值从Java文件传递到Javascript - How to Pass the hashmap value from a java file to Javascript 如何使用Rhino从Javascript中的Java HashMap获取值 - How to get values from a Java HashMap in javascript function using Rhino 从javascript获取呼叫无法到达Java REST服务 - fetch call from javascript unable to reach java REST service 如何从rest API高效并定期刷新bootstrap 4表的内容? - How to refresh efficiently and periodically the contents of a bootstrap 4 table from a rest API? 如何使用angular.js从Java REST服务发布数据 - How do I POST data from a Java REST service with angular.js 如何将Java脚本中的Json发布请求发送到apach CXF Rest Service - How to send Json post request from java script to apach CXF Rest Service
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM