Grails - 选择菜单不呈现 [英] Grails - Select menu not rendering

查看:136
本文介绍了Grails - 选择菜单不呈现的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我创建了2个下拉菜单,其中的第二个菜单根据第一个菜单进行动态更改。但是,第二个菜单不会显示更改,但在使用Firebug查看帖子时提供了正确的选项。



这是应该呈现菜单的函数

  def findSubtagsForTags(){
print Tag.getAll()

def tag = Tag.get(params.tag.id)

render(template:'subtagSelection',model:[subtags:tag.subtags])
}

这个方法在我的_form.gsp模板中调用,它由create.gsp调用(大部分都由grails脚手架生成) 。这是我调用它的代码片段

 < g:select name =tag.idfrom =$ {tag.list()}optionKey =idoptionValue =tagName
noSelection =['':'选择标签']
onchange =$ {remoteFunction(
controller:'tag',
action:'findSubtagsForTags',
params:'\'tag.id = \'+ this.value',
update:'subtagSelection'
)}/>

< td id =subtagSelectionvalign =top>
< select>
< option>选择标签< / option>
< / select>
< / td>

和正在呈现的子标签选择模板是

 < g:select name =subtag.idfrom =$ {subtags}optionValue =nameoptionKey =idid =subtags.id/ > 

页面上的第二个菜单始终是CHoose Tag,但使用Firebug时,该帖子已生成

 < select name =subtag.idid =subtags.id> 
< option value =1>培训< / option>
< option value =2>软件< / option>
< / select>

然而,第二个菜单没有改变。

在Firebug的Net Tab下,这是我的函数调用的'put'请求

 发布:
参数:tag.id 1
来源:
tag.id = 1

回应:

 < select name =subtagSelectionid = subtagSelection> 
< option value =1>培训< / option>
< option value =2>软件< / option>
< / select>

任何想法/解决方案?

编辑:在使用 https://stackoverflow.com/a/3771240/3691484 更改我的代码后,问题得到解决作为参考,改变模板文件和其他内容

解决方案

尝试一些修改 - 看看是否有所作为:

 < g:select name =tag.idfrom =$ {Tag.list()}optionKey =id optionValue =tagName
noSelection =['':'选择标记']
onchange =$ {remoteFunction(
controller:'tag',
action:' findSubtagsForTags',
params:'tag.id ='+ this.value,
update:'subtagSelection'
)}
/>

< td id =subtagSelection11valign =top>
< div id =subtagSelection>
optionKey =idnoSelection =['':'选择标签'] />
< / div>
< / td>

在select中有一个小问题select? - 当没有选择任何东西时使用noSelection标签


So I am creating 2 drop down menus, the 2nd of which dynamically changes based off the first. However, the 2nd menu does not render the change, but is providing the correct options when viewing the Post with Firebug.

Here is the function that is supposed to render the menu

def findSubtagsForTags(){
    print Tag.getAll()

    def tag = Tag.get(params.tag.id)

    render(template: 'subtagSelection', model:  [subtags: tag.subtags])
    }

This method is being called in my _form.gsp template, which is called by create.gsp (both generated by grails scaffolding for the most part). Here is my code snippet where I am calling it

<g:select name="tag.id" from="${Tag.list()}" optionKey="id" optionValue="tagName"
            noSelection="['':'Choose Tag']"
            onchange="${remoteFunction (
                    controller: 'tag',
                    action: 'findSubtagsForTags',
                    params: '\'tag.id=\' + this.value',
                    update: 'subtagSelection'
            )}" />

 <td id="subtagSelection" valign="top">
        <select>
        <option>Choose Tag</option>
        <g:select name="subtags.id" id="subtags.id" from="${[]}" optionKey="id"/>
        </select>
</td>

and the subtagSelection template that is being rendered is

<g:select name="subtag.id" from="${subtags}" optionValue="name" optionKey="id" id = "subtags.id"/> 

The 2nd menu on the page is always "CHoose Tag", but using Firebug, when I look at the post, this is generated

<select name="subtag.id" id="subtags.id" >
<option value="1" >Training</option>
<option value="2" >Software</option>
</select> 

however, there is no change to the 2nd menu.

Under the Net Tab of firebug, This is the 'put' request called by my function

Post:
    Parameters : tag.id 1
Source:
    tag.id=1

Response:

<select name="subtagSelection" id="subtagSelection" >
<option value="1" >Training</option>
<option value="2" >Software</option>
</select> 

Any ideas/solutions?

EDIT: Issue was resolved after changing my code around a little, using https://stackoverflow.com/a/3771240/3691484 as a reference, changing the template file among other things

解决方案

Try a few modifications - see if makes any difference:

<g:select name="tag.id" from="${Tag.list()}" optionKey="id" optionValue="tagName"
        noSelection="['':'Choose Tag']"
onchange="${remoteFunction (
        controller: 'tag',
        action: 'findSubtagsForTags',
        params: "'tag.id=' + this.value",
        update: 'subtagSelection'
    )}"
 />

<td id="subtagSelection11" valign="top">
<div id="subtagSelection">
<g:select name="subtags.id" id="subtags.id" from="[]"
optionKey="id" noSelection="['': 'Choose Tag']" />
</div>
</td>

There was a minor issue a select within a select? - use the noSelection tag for when nothing is selected

这篇关于Grails - 选择菜单不呈现的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆