grails - grails:如何在remoteFunction中传递参数

标签 grails

我想使用grails的remoteFunction进行参数设置。

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 Class org.codehaus.groovy.grails.web.taglib.exceptions.GrailsTagException Message Attribute value quote wasn't closed (action='edit' params="[date:${dp.date}]").



编辑 Action

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标记传递参数的正确方法是什么?

最佳答案

这也是有效的语法:

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

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

如果要在单击该行时将用户发送到编辑页面,则可以使用以下选项:
<tr onclick='document.location = "<g:createLink action='edit' params="${[date: dp.date]}"/>" '> ... </tr>

关于grails - grails:如何在remoteFunction中传递参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31980784/

相关文章:

grails配置log4j而不重建war?

hibernate - Grails临时域

grails - Grails中的URL映射前缀

grails - 双向在哪里? grails 一对一,双向测试(继续)

grails - 如何确保真正的一对多关系

grails - 使用Grails GORM和MySQL的乐观锁定异常

java - Grails 3.1 和 spring-security-core :3. 0.3

grails - 我们如何配置grails shiro plugin v1.1.3?

java - ehcache session 范围在 grails 中

grails - 服务验证域模型