john smith
john smith

Reputation: 190

How to display value of map which is also a map in <g:select> or <select> tag?

I have a map which is like this :

final static def BANK_NAMES = [
        bofa:[fullname:'Bank of America',hasPin:false],
        chase:[fullname:'Chase Bank',hasPin:false],
        wells:[fullname:'Wells Fargo Bank',hasPin:false],
        citi:[fullname:'Citibank',hasPin:false],
        us:[fullname:'US Bank',hasPin:false],
        usaa:[fullname:'USAA',hasPin:false],
        charles:[fullname:'Charles Schwab',hasPin:false]
]

I tried to display value in like this :

<g:each in="${BankConstants.BANK_NAMES}" var="banks">
<option id="status">${banks}</option>
</g:each>

and it shows like this :

bofa={fullname=Bank of America, hasPin=false}

Is there a way to show value of "fullname" in a or tag. Can anyone please help??

Upvotes: 1

Views: 107

Answers (2)

Belphegor
Belphegor

Reputation: 92

You can change

final static def BANK_NAMES = [
    [id: 'bofa', fullname:'Bank of America',hasPin:false],
    [id: 'chase', fullname:'Chase Bank',hasPin:false],
    [id: 'wells', fullname:'Wells Fargo Bank',hasPin:false],
    [id: 'citi', fullname:'Citibank',hasPin:false],
    [id: 'us', fullname:'US Bank',hasPin:false],
    [id: 'usaa', fullname:'USAA',hasPin:false],
    [id: 'charles', fullname:'Charles Schwab',hasPin:false]
]

so you wil have List of Maps. Then you have acces to fullname by:

${banks.fullname}

Edit: You can also try:

<g:each in="${BankConstants.BANK_NAMES.value}" var="banks">
    <option id="status">${banks.fullname}</option>
</g:each>

but I'm not sure if this will work.

Upvotes: 1

Kaffeleif
Kaffeleif

Reputation: 281

You can try:

<g:each in="${BankConstants.BANK_NAMES}" var="banks">
    <option id="status">${banks.value.fullname}</option>
</g:each>

Upvotes: 3

Related Questions