grails:如何在remoteFunction中传递params

时间:2015-08-13 06:17:08

标签: grails

我想使用grails的remoteFunction创建一个param。

HTML

 <table class="table table-hover table-bordered" id="profittable">
                        <thead>
                            <tr>
                              <th>Date</th>
                              <th>Profit</th>
                              <th>Delete?</th>
                            </tr>
                        </thead>
                        <tbody> 

                <g:each in="${dailyProfit}" var="dp">
                    <tr onclick="<g:remoteFunction action='edit' params="[date:${dp.date}]"></g:remoteFunction>" >
                        <td><g:formatDate format="yyyy-MM-dd" date="${dp.date}"/></td>
                        <td>
                                                    <g:formatNumber number="${dp.profit}" type="currency" currencyCode="PHP" format="###.##" />
                                                </td>
                                                <td>
                                                    <g:form controller="dailyProfit" action="delete" >
                                                        <g:hiddenField name="date" value="${dp.date.format("yyyy-MM-dd")}" />
                                                        <g:actionSubmit class="delete" value="Delete" >
                                                            <span class="glyphicon glyphicon-trash" aria-hidden="true"></span>
                                                        </g:actionSubmit>    
                                                    </g:form>
                                                </td>
                    </tr>
                </g:each>
                        </tbody>
                    </table>

错误消息

  

URI / SampleGrailsApp / dailyProfit / index类   org.codehaus.groovy.grails.web.taglib.exceptions.GrailsTagException   消息属性值报价未关闭(action ='edit'   PARAMS = “[日期:$ {dp.date}]”)

编辑操作

remoteFunction标签位于我表的每个tr中。计划是,如果单击该行,将显示编辑页面

def edit() {
    DateFormat format = new SimpleDateFormat("yyyy-MM-dd", Locale.ENGLISH);
    Date date = format.parse(params.date);
    def dailyProfit = DailyProfit.findByDate(date)
    render view:"edit" , model:[dailyProfit : dailyProfit]
}

 def update() {
    DateFormat format = new SimpleDateFormat("yyyy-MM-dd", Locale.ENGLISH);
    Date date = format.parse(params.date);
    def dailyProfit = DailyProfit.findByDate(date)
    if(dailyProfit){
        dailyProfit.properties = params
        dailyProfit.save(flush:true)
    }
    list() 
}

使用grails的remoteFunction标记传递参数的正确方法是什么?

2 个答案:

答案 0 :(得分:1)

你可以这样做。

<tr onclick = "${remoteFunction(
    controller: 'xyz',
    action: 'edit',update:'divId',
    params: [date: dp.date])}" >

答案 1 :(得分:0)

这也是一种有效的语法:

<tr onClick="<g:remoteFunction action='edit' params="${[param1: 'value', param2: 0]}"></g:remoteFunction>">.....</tr>

请注意,代码将转换为带有您指定参数的Ajax调用。作为Ajax调用,您不会看到页面更改。

如果要在单击行时将用户发送到编辑页面,则会出现以下选项:

<tr onclick='document.location = "<g:createLink action='edit' params="${[date: dp.date]}"/>" '> ... </tr>
相关问题