Two Methods for loading JSON from Action in combobox in Easyui

Source: Internet
Author: User

{"total":28,"rows":[{"productid":"FI-SW-01","productname":"Koi"},{"productid":"K9-DL-01","productname":"Dalmation"},{"productid":"RP-SN-01","productname":"Rattlesnake"},{"productid":"RP-LI-02","productname":"Iguana"},{"productid":"FL-DSH-01","productname":"Manx"},{"productid":"FL-DLH-02","productname":"Persian"},{"productid":"AV-CB-01","productname":"Amazon Parrot"}]}

The Json format of combobox loading is as follows:

[{"productid":"FI-SW-01","productname":"Koi"},{"productid":"K9-DL-01","productname":"Dalmation"},{"productid":"RP-SN-01","productname":"Rattlesnake"},{"productid":"RP-LI-02","productname":"Iguana"},{"productid":"FL-DSH-01","productname":"Manx"},{"productid":"FL-DLH-02","productname":"Persian"},{"productid":"AV-CB-01","productname":"Amazon Parrot"}]


Combobox loading JSON method 1: Output JSON

JSONArray json = JSONArray. fromObject (list); System. out. println (json. toString (); response. setCharacterEncoding ("UTF-8"); // specify as utf-8response.getWriter (). write (json. toString (); // convert to JSOn format

In jsp code

$('#cc').combobox({       url:'load!queryCpersontype',       valueField:'code',       textField:'note'  }); 

: Although the output JSON does not meet the requirements, the jsp page is transitioned to conform to the requirements

JSONObject jobj = new JSONObject (); // a new JSONjobj. accumulate ("rows", list); // row indicates the data log.info of the displayed page ("JSON format:" + jobj. toString (); response. setCharacterEncoding ("UTF-8"); // specify as utf-8response.getWriter (). write (jobj. toString (); // convert to JSOn format

In jsp code

 $.ajax({   type: "POST",   url: "load!queryCpersontype",   dataType:"json",   success: function(json){     $("#cc").combobox({ data:json.rows, valueField:'code',     textField:'note' });   } });


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.