我需要根据用户在g:select中选择的值,使用服务器上的值更新textField的值。在代码中:
<g:select name="description" from="${momentum.MoneyTransType.prodList}" value="${moneyInstance?.description}"
noSelection="['':'-Select Description-']" onChange="${remoteFunction(action:'setHowMuch', update:[success:'howMuch', failure:'failure'],
params:'\'selection=\' + this.value', options=[asynchronous:false])}"/>
<g:textField id="howMuch" name="howMuch" value="${moneyInstance?.howMuch}"/>
它不起作用。如果我给出“更新:[成功:”一个div id,一切都很好,但那不是我想要的。我需要允许用户输入自由流程描述(我将在另一个文本字段中输入)和自由流量。我想我可以隐藏div然后通过jQuery监听对div的更改,然后更新textField的数量。我是否可以使用remoteFunction“更新”功能或使用其他grails功能更新textField?
奇怪的是,使用jQuery更改函数放入一个临时的'toHide'div不能更新textField,即后续警报等没有触发:
$('#toHide').change(function() {
alert(" I got changed, value:");
$("#howMuch").text($(this).val());
});
答案 0 :(得分:1)
好吧,在写完以下内容之后,我重读了你的问题并看到你声明你知道它适用于div。所以我的答案的其余部分可能没有帮助,但使用div有什么问题?空div不会显示任何内容,因此您无需隐藏它。所以FWIW:
<g:textField ...>
放入模板中。 在您希望呈现模板的位置添加div。其他
单词,将当前<g:textField ..>
替换为<div id=updateme name=updateme></div>
在你的setHowMuch动作中,渲染模板。
例如,我这样做:
在视图中:
<g:select class='setTagtypeValue-class'
name='tagtype-${i}-header'
from="${org.maflt.ibidem.Tagtype.list(sort:'tagtype').groupBy{it.tagtype}.keySet()}"
value="${setTagtypeValue?.tagtype?.tagtype}"
valueMessagePrefix="tagtype"
noSelection="${['null':'Select One...']}"
onchange="${remoteFunction(action:'options', update:'tagtype-options-${i}',
params:'\'tagtype=\' + this.value +\'&i=${i}\'' )}" />
控制器操作:
def options = {
def i = params.i ?: 0
def tagtypes = Tagtype.findAllByTagtype(params.tagtype)
render(template:"tagtypeList", model:[tagtypes:tagtypes,i:i])
}
tagypeList模板:
<table>
<tr>
<th></th>
<th><g:message code="tagtype.lookup"
default="Lookup Table" /></th>
<th><g:message code="tagtype.regexpression"
default="Field Rule" /></th>
<th><g:message code="tagtype.uicomponent"
default="UI Component" /></th>
</tr>
<g:each in="${tagtypes}" var="tagtype" status="j">
<tr>
<td><g:radio name="setTagtypesList[${i}].tagtype.id" value="${tagtype.id}"
checked="${(setTagtypeValue?.tagtype?.id == tagtype.id ||
(!setTagtypeValue?.tagtype?.id && j==0))}"></g:radio></td>
<td>${tagtype.lookupTable}</td>
<td>${tagtype.regexpression}</td>
<td><g:message code="${'uicomponent.' + tagtype.uicomponent.id}"
default="${tagtype.uicomponent.uicomponent}" />
</td>
</tr>
</g:each>
</table>
此代码来自http://www.maflt.org/products/Ibidem中的元数据集(在UI中设置称为字段)屏幕。