gpt4 book ai didi

javascript - 在Javascript中获取域类值(gsp)

转载 作者:行者123 更新时间:2023-12-02 15:31:36 25 4
gpt4 key购买 nike

我想将域类中设置的所有值检索到客户端(gsp或Javascript)
假设我有一个名为GeneralSetting的域类。我使用的方法有效,但并非完全符合我的要求。

gsp文件

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

s
console.debug('${test}');输出:[com.domain.GeneralSetting:1] console.debug('${test1}');输出:红色

我在想这样的事情:
def globalSettings = com.digithurst.gutmann.domain.GeneralSetting.getAll()[0]
def array = []

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

但是当我输出数组时,我只是一直得到这个:[com.domain.GeneralSetting:1]而不是所有属性

最佳答案

试试这个..

<%@ 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
%>

和js部分一样
console.debug('${json}'); 
console.debug('${json1}');

然后
JSON.parse('${json}')
JSON.parse('${json1}')

关于javascript - 在Javascript中获取域类值(gsp),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18460451/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com