使用Grails JSON数据Angularjs NG-网 [英] Angularjs ng-grid using Grails JSON data
问题描述
角纳克网数据绑定问题
我有对我已经注册了一个自定义的编组,以产生,我可以用一个Angularjs NG-电网JSON域网格类一个Groovy / Grails应用程序。
I have a Groovy/Grails application that has a domain "Grid" class for which I have registered a custom "marshaller" to produce the JSON that I can use for an Angularjs ng-grid..
说网格是和实例,
网格为JSON生成所需的JSON。
Say "grid" is and instance of the Grid class, "grid as JSON" produces the desired JSON.
我有加载数据并返回JSON一个Grails / Groovy的控制器:
I have a Grails/groovy controller that loads the data and returns the JSON:
def index() {
def grid = Grid.first()
grid as JSON
}
但我不知道如何让我这个GSP JSON数据到NG-网:
But I don’t know how to get this JSON data into the ng-grid in my GSP:
<body ng-controller="MyCtrl">
<script>
var app = angular.module('myApp', ['ngGrid']);
app.controller('MyCtrl', function($scope) {
$scope.gridOptions = ${grid}; // NEED HELP HERE !
});
</script>
<div class="gridStyle" ng-grid="gridOptions"></div>
</body>
我不知道如何获取数据到$ scope.gridOptions。当我看到正与萤火虫产生什么,我看$ scope.gridOptions是
I don't know how to get the data into $scope.gridOptions. When I look at what is being generated with firebug, I see $scope.gridOptions is
{"columnDefs":[{"field": ...
这是EN codeD JSON数据。 (引号都设有codeD)。什么是传递一个Grails后端和NG-格在JSP之间JSON数据的最佳方式?
which is the encoded JSON data. (The quotation marks are encoded). What is the best way to pass JSON data between a Grails back end and ng-grid in a JSP?
推荐答案
感谢你的建议斯里达尔,我开始寻找在普惠制的方式来未逃脱JSON,我在这里找到了答案:
Thank you for the suggestion Sridhar, I started looking for ways to un-escape JSON within GSP, and I found the answer here:
<一个href=\"http://aruizca.com/how-to-render-json-properly-without-escaping-quotes-inside-a-gsp-script-tag/\"相对=nofollow>如何到渲染JSON-正确且不转义引号,里面-A-GSP-脚本标记
我需要使用G:在我申请GSP codeC标记:
I need to use the g:applyCodec tag in my GSP:
<g:applyCodec encodeAs="none">
$scope.gridOptions = ${grid};
</g:applyCodec>
这篇关于使用Grails JSON数据Angularjs NG-网的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!