gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-02 15:23:22 25 4
gpt4 key购买 nike

我想使用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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com