如何添加多个g:select [英] how to add multiple g:select

查看:122
本文介绍了如何添加多个g:select的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

http://www.4shared.com/下载/ 8Q8J5E2Z / 122.PNG?tsid = 20130924-025921-5796ea2b



当点击按钮ADD时,在combobox下面用户会再次添加一个组合框...与JavaScript ..



我不知道该怎么做。昨天晚上我试着用jQuery时......但它不能被追加...

 < g:select name =user.idfrom =$ {userdetailsList?.firstName}noSelection = [ '': '用户']/> 


< html>
< head>
< g:set var =entityNamevalue =$ {message(code:'CurrencyList.label',default:'CurrencyList')}/>
< title>< g:message code =default.list.labelargs =[entityName]/>< / title>
< / head>
< body>
< div id =userMessageclass =infostyle =color:orange; background-color:#d0e4fe;> $ {flash.message}< / div>
< / g:if>
< table align =left>
< tbody>
< tr>
< td style =font-size:20px; colspan =3>< b>组添加< / b>< / td>
< / tr>
< tr>
< td width =70>名称< / td>
< td width =5>:< / td>
< td>< g:textField name =namagrupvalue =$ {nama}/>< / td>
< / tr>
< tr>
< td>说明< / td>
< td>:< / td>
< td>< g:textArea name =deskripsigrupvalue =myValuerows =5cols =40/>< / td>
< / tr>
< tr>< / tr>

< / tbody>
< / table>
< ol>
< h3>使用者< / h3>
< br>
< div id =choose>< g:select name =user.id
from =$ {userdetailsList?.firstName}
noSelection =[ ':'User']/> < / DIV>
<按钮>添加< /按钮>
< br>
< / ol>
< / body>
< / html>


解决方案

一种解决方案可以是对控制器,并在该方法返回所有选项g.select。



类似于以下内容应该工作...



在你的'Add'按钮中添加对onclick属性中函数的调用,并在这个函数中添加...

  $。ajax({
url:$ {createLink(action:'loadSelect')},
success:function(data,status){
$(选择)。append(data);
}
})

另外

 < div id =choose>创建一个ID为'selected'的div, < / DIV> 

并在您的控制器中添加...

  def loadSelect(){
//无论您需要什么数据...
render< g:select name ='user.id' from ='$ {userdetailsList?.firstName}'noSelection ='[\'\':\'User\\'']'/>
}

没有测试过,所以试试吧,告诉我你是否需要更多帮助

编辑:回答您的代码
如果我理解正确,您只需要'克隆'select以便能够将多个用户添加到组。在这种情况下,您不需要再次访问控制器和数据库来生成新的选择。

 < html> 
< head>
< g:set var =entityNamevalue =$ {message(code:'CurrencyList.label',default:'CurrencyList')}/>
< title>< g:message code =default.list.labelargs =[entityName]/>< / title>
< script type =text / javascript>
function addSelect(){
$(#selects)。append($(#firstSelect)。clone());
}
< / script>
< / head>
< body>
< div id =userMessageclass =infostyle =color:orange; background-color:#d0e4fe;> $ {flash.message}< / div>
< / g:if>
< table align =left>
< tbody>
< tr>
< td style =font-size:20px; colspan =3>< b>组添加< / b>< / td>
< / tr>
< tr>
< td width =70>名称< / td>
< td width =5>:< / td>
< td>< g:textField name =namagrupvalue =$ {nama}/>< / td>
< / tr>
< tr>
< td>说明< / td>
< td>:< / td>
< td>< g:textArea name =deskripsigrupvalue =myValuerows =5cols =40/>< / td>
< / tr>
< tr>< / tr>

< / tbody>
< / table>
< ol>
< h3>使用者< / h3>
< br>
< div id =choose>< g:select id =firstSelectname =user.id
from =$ {userdetailsList?.firstName}
noSelection =['':'User']/> < / DIV>
< button onclick =addSelect()> ADD< / button>
< br>
< / ol>
< / body>
< / html>


http://www.4shared.com/download/8Q8J5E2Z/122.PNG?tsid=20130924-025921-5796ea2b

when a click button "ADD", below combobox User will append a combobox again...with javascript..

i don't know how to do it..when i tried with jQuery last night..but it cannot be append...

<g:select name="user.id" from="${userdetailsList?.firstName}" noSelection="['':'User']"/>


<html>
    <head>
        <g:set var="entityName" value="${message(code: 'CurrencyList.label', default: 'CurrencyList')}" />
        <title><g:message code="default.list.label" args="[entityName]" /></title>          
    </head>
    <body>  
    <g:if test="${flash.message}">
        <div id="userMessage" class="info" style="color:orange;background-color:#d0e4fe;">${flash.message}</div>
    </g:if>
    <table align="left">
    <tbody>
        <tr>
            <td style="font-size:20px;" colspan="3"><b>Group Add</b></td>
        </tr>
        <tr>
            <td width="70">Name</td>
            <td width="5">:</td>
            <td><g:textField name="namagrup" value="${nama}" /></td>
        </tr>
        <tr>
            <td>Description</td>
            <td>:</td>
            <td><g:textArea name="deskripsigrup" value="myValue" rows="5" cols="40"/></td>
        </tr>
        <tr></tr>

    </tbody>    
</table>
        <ol>
        <h3 >User</h3>
        <br>
        <div id="selects"><g:select name="user.id" 
                    from="${userdetailsList?.firstName}"  
                    noSelection="['':'User']" /> </div>
        <button>ADD</button>  
        <br>
        </ol>
    </body>
</html>

解决方案

One solution could be to make an Ajax call to the controller and in that method return the g.select with all the options.

Something similar to the following should work...

Add in your 'Add' button a call to a function in the onclick attribute, and inside this function add...

$.ajax({
   url: "${createLink(action:'loadSelect')}",
   success: function(data, status){
       $("#selects").append(data);
   }
})

Also create a div with id 'selects' so the selects can be appended there.

<div id="selects"></div>

And in your controller add...

def loadSelect(){
    // whatever you need to get the data...
    render "<g:select name='user.id' from='${userdetailsList?.firstName}' noSelection='[\'\':\'User\']'/>"
}

Haven't tested it, so try it and tell me if you need more help

Edit: Answer to your code If I have understood right, you just need to 'clone' the select to be able to add several users to a group. In this case you don't need to go again to the controller and database to generate a new select.

<html>
    <head>
        <g:set var="entityName" value="${message(code: 'CurrencyList.label', default: 'CurrencyList')}" />
        <title><g:message code="default.list.label" args="[entityName]" /></title>  
        <script type="text/javascript">
            function addSelect(){
                 $("#selects").append($("#firstSelect").clone());
            }
        </script>        
    </head>
    <body>  
    <g:if test="${flash.message}">
        <div id="userMessage" class="info" style="color:orange;background-color:#d0e4fe;">${flash.message}</div>
    </g:if>
    <table align="left">
    <tbody>
        <tr>
            <td style="font-size:20px;" colspan="3"><b>Group Add</b></td>
        </tr>
        <tr>
            <td width="70">Name</td>
            <td width="5">:</td>
            <td><g:textField name="namagrup" value="${nama}" /></td>
        </tr>
        <tr>
            <td>Description</td>
            <td>:</td>
            <td><g:textArea name="deskripsigrup" value="myValue" rows="5" cols="40"/></td>
        </tr>
        <tr></tr>

    </tbody>    
</table>
        <ol>
        <h3 >User</h3>
        <br>
        <div id="selects"><g:select id="firstSelect" name="user.id" 
                    from="${userdetailsList?.firstName}"  
                    noSelection="['':'User']" /> </div>
        <button onclick="addSelect()">ADD</button>  
        <br>
        </ol>
    </body>
</html>

这篇关于如何添加多个g:select的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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