2010-11-09 53 views
1

當我提交AJAX請求時,我對處理服務器的響應感到困惑。我想要做的是通過清除表格並插入新表格來更新表格。訪問AJAX響應並用新值更新表格

控制器的下面的代碼給出了一個resonse到AJAX請求,三倍是一個列表:

def resultsAjax = { 
    def triples = linkedDataService.getRemoteTriplesTable("Student4") 
    render(template:'tripleResultsTable', model:[triples:triples]) 
} 

這是以下形式:

<g:form action="results"> 
    <label for="id">Resource ID </label> 
    <g:textField name="id" /> 
    <g:submitToRemote value="search" update="resultsAjax" 
        url="[controller:'tripleProperty', action:'resultsAjax']"/> 
</g:form> 

和下表:

<g:render id="resultsAjax" template="tripleResultsTable" model="${triples}"/> 

如何訪問服務器響應的列表?

編輯:

它的工作或多或少,但奇怪的是,該表沒有更新,但新的值是在桌子上......

alt text

模板僅僅是這樣的:

<g:each in="${triples}" status="i" var="tripleProperty"> 
<tr class="${(i % 2) == 0 ? 'odd' : 'even'}"> 

    <td>${tripleProperty.property}</td> 

    <td>${tripleProperty.value}</td> 

</tr> 

是否需要比渲染(模板..)更多的代碼才能替換表中的值?

回答

1

你的tripleResultsTable.gsp模板是什麼樣的?你可能模型屬性看起來像這樣

<g:render id="resultsAjax" template="tripleResultsTable" model="${[triples:triples]}" /> 

然後在你的模板,你可以使用

<g:each in="${triples}">...</g:each> 

到輸出中你想

歡呼

的TR/TD元素