Grails: loading data on one ComboBox depending on another

Say I have a combo box with the options GENERAL, AIR, GROUND and SEA

<g:select name="group" from="${['GENERAL', 'AIR', 'GROUND', 'SEA']}" valueMessagePrefix="default.category" value="${tipoN}" />

And then another combo box that loads certain information depending on whether you choose GENERAL, AIR, GROUND or SEA.

For example, GROUNDit has 3 options, FedEx, USPS, DHLbut AIRhas a completely different AIRPLANE, JET, HOT AIR BALLOON.

The name of the other <g:select>must be"commodity"

I thought about creating a javascript file and viewed everything as HTML, but I did some research on Google and is not as simple as I thought.

Does anyone know what would be the best way to do this? Thanks in advance!

FG

+3
source share
3

, AJAX . - :

// grails-app/domain/ShippingOption.groovy

class ShippingOption = {
    String method, // can be 'ground', 'sea', 'air', or 'general'
           name    // can be 'fedex', 'ups', etc.

    def options = {
        def meth = params.method ?: "general"
        def comList = ShippingOption.findByMethod(meth)
        render(template:"shippingList", model: [ commodityList: comList ])
    }
}

:

<!-- grails-app/views/_shippingList.gsp -->
<g:each var="opt" in="${commodityList}">
    <option value="${opt.name}">${opt.name}</option>
</g:each>

gsp :

<!-- ... other stuff is before here ... -->
<g:select name="method" from="${['GENERAL', 'GROUND', 'SEA', 'AIR']}"
    onchange="${remoteFunction(action:'options', update:'commodity', 
        params:''method=' + this.value' )}" />
<select id="commodity"></select>

, - , . .

, ShippingOption s. .

["fedex", "ups"].each { name ->
    def so = new ShippingMethod(method: "ground", name: name )
    so.save()
}

PS: .

: remoteFunction, g: , templates AJAX

+3

. , , , , , , "" , JavaScript.

0

Source: https://habr.com/ru/post/1766021/


All Articles