javascript - Grails在JavaScript中调用application.config值

标签 javascript grails app-config

如何在javascript中的应用程序配置中调用值集?我尝试使用jquery并将其放在我的JavaScript中,但是它不起作用。甚至没有jquery也能做到吗?请帮忙

console.log("${grailsApplication.config.getProperty('wipTransportUI.rtdService.url', String)}");

最佳答案

您的示例使用Grails 3对我有用,我在application.yml中添加了以下内容:

wipTransportUI:
    rtdService:
        url: 'aUrl'

然后在gsp中的javascript中使用:
<script type="text/javascript">
    console.log( "${grailsApplication.config.getProperty( 'wipTransportUI.rtdService.url', String )}" );
</script>

安慰:

enter image description here

如果您使用的是Grails 2,则将以不同的方式访问属性:
console.log( "${grailsApplication.config.wipTransportUI.rtdService.url}" );

关于javascript - Grails在JavaScript中调用application.config值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43161364/

相关文章:

c# - .Net app.config 文件在 c :\ProgramFiles\下被忽略

javascript - Chrome 扩展程序 : Insert text into textfield when clicking button in pop-up

javascript - 如何将 kotlin 与 Node.js 集成

javascript - 在 NodeJS http 中发送 HTTP POST 数据

grails - removeFrom* 不工作且没有错误

grails - 在grails中,如何使用gsp从一组域对象中构建一个用逗号分隔的链接列表?

c# - "An error occurred creating the configuration section handler for"-

.net - .Net 程序集的 App.config 从 PowerShell 运行

javascript - 操作在后端还是前端?

grails - 如何覆盖 ApplicationTagLib#createLink 和 g :link? 的标准行为