简体   繁体   中英

Java HashMap key to jQuery

How can i access the HashMap key to the JQuery ? I want to have the key it self to use in typeahead of bootstrap .

I'm using Gson to parse the HashMap to Gson:

HashMap<String, String> source = new HashMap<String, String>();
put("key","value");

response.setContentType( "application/json" );
response.setCharacterEncoding( "UTF-8" );
response.getWriter().write( new Gson().toJson( source ) );

Code of my typeahead:

$('#textbox').typeahead({
    source: function(query, process){
        return $.get('URL', {query: query},
                      function(data){
              return process(data.key);
              },'json');
        },
    items: 10
});

at return process(data); i want to have the key of the HashMap it self

为什么它极有可能。

just use JSON.stringfy(data.key);

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM