1

我正在尝试将 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>
4

1 回答 1

0

一切似乎都很好。你看到任何错误吗?或您可以告诉我们的任何输出。

请参阅此链接以获得更好的描述: Best method for passing Data from Java/JSF2 bean to Javascript/jQuery Components as return values

于 2012-08-30T07:30:48.730 回答