load parts of a JSON in many divs + Struts2

点点圈 提交于 2019-12-07 17:55:31

问题


I need load the content of a Object JSON in many divs, but in parts. For example,

My JSON structure:

{"Example": {
   "Hi": "hi",
   "Bye": "bye"
 }
}

Assuming that the JSON string successfully load my JSP page. I am trying to load the contents of the JSON like this:

(For the attribute Hi and Bye)

<sj:div id="div1" dataType = "json">
    <s:property value="Example.Hi"/>
</sj:div>

<sj:div id="div2" dataType = "json">
    <s:property value="Example.Bye"/>
</sj:div>

Struts.xml:

    <action name="name" class="class" method="method">
        <result type="json">
            <param name="root">
                Example
            </param>
        </result>
    </action>

but this doesn't work... What I can do?

I'm using: Struts2 Jquery Library


回答1:


You should build the URL like

<s:url var="remoteurl1" action="name"><s:param name="div1" value="true"/></s:url>
<sj:div id="div1" href="%{#remoteurl1}" dataType = "json"/>

<s:url var="remoteurl2" action="name"><s:param name="div2" value="true"/></s:url>
<sj:div id="div2" href="%{#remoteurl2}" dataType = "json"/>

Then in your action you check if isDiv1() or isDiv2() and return corresponding result.



来源:https://stackoverflow.com/questions/21167826/load-parts-of-a-json-in-many-divs-struts2

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!