【问题标题】:Passing JSON from Grails Controller to d3 - how to get the .gsp side working?将 JSON 从 Grails 控制器传递到 d3 - 如何让 .gsp 端正常工作?
【发布时间】:2014-08-13 10:28:18
【问题描述】:

我想将来自 grails 控制器的映射作为 JSON 传递给 d3,并使用 d3.json() 方法对其进行解析

我的控制器看起来像这样

    def graph() {

      def map = [[source: "NodeOne", "target": "NodeTwo", "type": "type"],
        ["source": "NodeOne", "target": "NodeThree", "type": "type"]]

      render map as JSON
    }

gsp 脚本端如下所示:(d3 示例 http://bl.ocks.org/mbostock/4062045)。 d3.json() 在 URL 处渲染一个 json

 d3.json( URL , function(error, graph) {...[more code here]...}

为了让我的地图在 d3 中呈现,我需要为 URL 输入什么?当我创建到控制器的链接时,不是加载视图,而是将 JSON 打印为文本。

【问题讨论】:

    标签: javascript json grails d3.js


    【解决方案1】:

    未测试以下代码:希望对您有所帮助 在你的 XX.gsp 中

    <script>
    var url = "${createLink(controller:'yourControllerName',action: 'graph') }";
    d3.json( url , function(error, graph) {...[more code here]...}
    </script>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-05-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-05-21
      • 2015-07-07
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多