g:选择onchange with rest-url
我想选择一个带有<g:select>
标记的语言,并在选择更改时将选择参数发送到某个操作。 (帕拉姆应在打开视图的URL中可见)g:选择onchange with rest-url
我试图和<g:form>
不同的变化<g:select>
:
-
版本创建正确的参数,可以但不创建一个REST URL :
<g:form name="selectLanguage" <b>action='show' id="${mitarbeiterprofilInstance.id}" lang=lang> <g:select onchange="submit();" value="${profilInstance?.sprache?.sprache}" name="lang" optionKey="sprache" optionValue="sprache" from = "${mitarbeiterprofilInstance.profiles.sprache}" /> </g:form>
PARAMS:
[lang:deutsch, id:3, action:show, controller:mitarbeiterprofil]
网址:
/mitarbeiterprofil/show/3
网址应该是
/mitarbeiterprofil/show/3/deutsch
-
版本增加了PARAMS的url,但与错误的行动:
<g:form name="selectLanguage" id="${mitarbeiterprofilInstance.id}" lang=lang> <g:select onchange="submit();" value="${profilInstance?.sprache?.sprache}" name="lang" optionKey="sprache" optionValue="sprache" from = "${mitarbeiterprofilInstance.profiles.sprache}" /> </g:form>
PARAMS:
[lang:deutsch, id:3, action:index, controller:mitarbeiterprofil]
网址:
/mitarbeiterprofil/index/3/deutsch
-
版本选择合适的控制器,显示在URL中的参数,可以但不使用正确的参数:
<g:form name="selectLanguage" id="${mitarbeiterprofilInstance.id}" lang=lang> <g:select onchange="submit(<b>action='show');" value="${profilInstance?.sprache?.sprache}" name="lang" optionKey="sprache" optionValue="sprache" from = "${mitarbeiterprofilInstance.profiles.sprache}" /> </g:form>
PARAMS:
[lang:show, id:3, action:show, controller:mitarbeiterprofil]
网址:
/mitarbeiterprofil/show/3/show
有谁还有另一个想法,我可能会怎么做呢?
你必须与UrlMappings.groovy
首先这里打球,让我们调整形式:
<g:form name="selectLanguage" action='show' id="${mitarbeiterprofilInstance.id}" >
<g:select onchange="submit();"
value="${profilInstance?.sprache?.sprache}"
name="lang"
optionKey="sprache"
optionValue="sprache"
from = "${mitarbeiterprofilInstance.profiles.sprache}" />
</g:form>
和映射:
"/mitarbeiterprofil/show/$id/$lang" (controller:"mitarbeiterprofil", action:"show")
这可以解决你的问题,但我'疑问...所以试试看,并告诉我们结果:)
P.S.这里的问题在渲染过程中。您的动作网址将在用户选择语言之前创建。所以你必须更新网址,每次用户选择语言或它会导致像这样的网址:/ mitarbeiterprofil/show/3?lang = en
嗨,ive在你的代码中做了Url-Mappings,但没有效果...只有通过直接通过url或其他视图访问操作才能显示正确的Url,但不能使用g:select。 – fabschu