简体   繁体   English

java对象到json字符串以构建jqmobile嵌套列表

[英]java object to json string to build jqmobile nested list

Below is my object structure, I get the list of OrganizationVO from db. 下面是我的对象结构,我从db获取OrganizationVO的列表。 Could some one suggest how to convert this list to JSON format ? 有人可以建议如何将此列表转换为JSON格式吗?

class OrganizationVO {
    String name;
    int id;
    String mgrName;

    List<OrganizationVO> orgvo;
}        

Below is the script and template code I am using to generate the nested list, I am able to see the nested hierarchy in the static form where the child nodes are displayed within the root node. 下面是我用来生成嵌套列表的脚本和模板代码,我能够看到静态形式的嵌套层次结构,其中子节点显示在根节点内。 Please suggest how to get the drill down effect of nested nodes and also use the data-filter option. 请提出如何获得嵌套节点的向下钻取效果以及如何使用数据过滤器选项的建议。

$(function () {
         $("#template").tmpl(clientData).appendTo("#target");
});


<script type="text/x-jquery-tmpl" id="template">

<li data-theme="b" class="ui-btn ui-btn-icon-right ui-li ui-li-has-alt ui-btn-up-a"> 
<div class="ui-btn-inner ui-li ui-li-has-alt"> 
    <div class="ui-btn-text"> 
<a href="#${organizationID}" class="ui-link-inherit">
<h3>
    ${organizationName}</h3>
 </a>

    {{if organizationList}}
    <div>
        <ul> 
        {{each(i, child) organizationList}} 
            <li> 
            {{tmpl(child) "#template" }}
            </li>
        {{/each}}
     </ul>
    </div>
    {{/if}}
    </div></div>
    </li> 
    </script>

Your best option is Flexjson. 最好的选择是Flexjson。 You'll have to ensure your object conforms to the java bean standard, but it's really easy to use: http://flexjson.sourceforge.net Oh and its faster that GSON. 您必须确保您的对象符合Java Bean标准,但它确实非常易于使用: http ://flexjson.sourceforge.net哦,它的GSON速度更快。

I highly recommend using Gson: http://code.google.com/p/google-gson/ 我强烈建议您使用Gson: http : //code.google.com/p/google-gson/

It's relatively painless 相对没有痛苦

Please read the jQM docs on JSON and Creating Dynamic pages 请阅读JSON和创建动态页面上的jQM文档

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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