在很多div + Struts2中加载JSON的一部分 [英] load parts of a JSON in many divs + Struts2
本文介绍了在很多div + Struts2中加载JSON的一部分的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要在多个div中加载对象JSON的内容,但是在部分内容中。例如,
我的JSON结构:
Hi:hi,
Bye:bye
}
}
假设JSON字符串成功加载我的JSP页面。我试图加载JSON的内容,如下所示:
(对于属性 Hi
和 b
$ b
< sj:div id =div1dataType =json >
< s:property value =Example.Hi/>
< / sj:div>
< sj:div id =div2dataType =json>
< s:property value =Example.Bye/>
< / sj:div>
Struts.xml:
< action name =nameclass =classmethod =method>
< result type =json>
< param name =root>
示例
< / param>
< / result>
< / action>
但这不起作用...我能做什么?
我正在使用:Struts2 Jquery Library
解决方案
>
< s:url var =remoteurl1action =name>< s:param name =div1value = 真/>< /秒:URL>
< sj:div id =div1href =%{#remoteurl1}dataType =json/>
< sj:div id =div2href =%{#remoteurl2}dataType =json/>
然后在您的操作中检查 isDiv1()
或 isDiv2()
并返回相应的结果。
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
解决方案
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.
这篇关于在很多div + Struts2中加载JSON的一部分的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文