0

I want to retrieve ALL values set in my domain class to the client side (gsp or Javascript) Let's say I have a domain class named GeneralSetting. The approach I used works but not completely how I want.

gsp file

<%
def test = com.domain.GeneralSetting.findAll()[0]
def test1 = com.domain.GeneralSetting.findAll()[0].color
%>

Js

console.debug('${test}'); OUTPUT: [com.domain.GeneralSetting : 1] console.debug('${test1}'); OUTPUT: red

I was thinking about something like this:

def globalSettings = com.digithurst.gutmann.domain.GeneralSetting.getAll()[0]
def array = []

//Add all properties
 globalSettings.each {
        array.add(it);
    }

But when I ouput the array i just keep getting this: [com.domain.GeneralSetting : 1] instead of all the properties

1 Answer 1

1

try this..

<%@ page import="grails.converters.JSON" %>

<%
def test = com.domain.GeneralSetting.findAll()[0] 
def json  = test as JSON
def test1 = com.domain.GeneralSetting.findAll()[0].color
def json1  = test1 as JSON
%>

and js part like

console.debug('${json}'); 
console.debug('${json1}');

then

JSON.parse('${json}')
JSON.parse('${json1}')
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.