我正在尝试将 Json 作为回调参数传递。任何人都可以更正 javascript 以从 json 对象中获取值吗?
javascript
function renderTopic(xhr,status,args){
alert("iam In renderTopic");
var topicObject = $.parseJSON(args.topicJSON);
for(var x in topicObject){
alert(x.topicBody);
};
}
服务器端
jGenerator.writeFieldName("topicBody");
jGenerator.writeStartArray();
...............
jGenerator.close();
context = RequestContext.getCurrentInstance();
System.out.println("JSON output in string "+out.toString())
xhtml
<p:commandLink action="#{topicController.listAllTopics}"
id="topicListAllCmdLink" value="" oncomplete="javascript:renderTopic(xhr, status,args)"/>
http响应
<partial-response><changes><update id="javax.faces.ViewState"><![CDATA[4091946826703479326:-2361306414195161728]]></update><extension ln="primefaces" type="args">{"topicJSON":"{\"topicBody\":[\"Test10\",\"Test22\",\"Test4\",\"Test11\"]}"}</extension></changes></partial-response>