我正在使用 GGTS:3.6.4,
chalice :2.4.4
JDK 1.7.51
谷歌可视化:1.0
我正在尝试将数据从域类传递到我的 View ,以使用 Google 可视化插件显示 map 。我相信我错误地将这些数据传递给我的 GSP。我可以将数据以可接受的格式以文本形式呈现在屏幕上,请参阅我的 GSP 以获得 def mapData .
当我使用
def mapData =[<g:each in="${places}" var="place" status="i">[${place.lat}, ${place.lon}, "${place.name }"],</g:each>]
我收到此错误:
消息:属性值引用未关闭(elementId="map"columns= "${mapColumns}"data= "[
关于如何更改我的 GSP 以从我的域类中获取数据的任何提示?
域类:
package zmapapp
class ThingLoc {
String name
Float lat
Float lon
static constraints = {
lat()
lon()
name()
}
}
Controller :
package zmapapp
class ThingLocController {
def scaffold = true
def map (){
def places = ThingLoc.list()
[places: places]
}
}
普惠制:
<html>
<head>
<title>Google Visualization API plugin</title>
<meta name="layout" content="main" />
<gvisualization:apiImport/>
</head>
<body>
<%
def mapColumns = [['number', 'Lat'], ['number', 'Lon'], ['string', 'Name']]
def mapData = [[37.4232, -122.0853, 'Work'], [37.4289, -122.1697, 'University'], [37.6153, -122.3900, 'Airport'], [37.4422, -122.1731, 'Shopping']]
%>
<script type="text/javascript">
function selectHandler(e) {
alert('A table row was selected');
}
function readyHandler(e) {
console.log('Table is ready');
}
</script>
<h2>See Map Below </h2>
<gvisualization:map elementId="map"
columns= "${mapColumns}"
data= "${mapData}" />
<table cellpadding="2" cellspacing="0">
<td>
<a href="http://developers.google.com/chart/interactive/docs/gallery/map">Map</a>
</td>
<td>
<div id="map" style="width: 400px; height: 300px"></div>
</td>
</tr>
</table>
[<g:each in="${places}" var="place" status="i">[${place.lat}, ${place.lon}, "${place.name }"],</g:each>]
</body>
最佳答案
我最终没有使用 def mapColumns 或 mapData,而是使用了此处找到的 google 语法:https://developers.google.com/chart/interactive/docs/gallery/map
这是我的更新 gsp:
<html>
<head>
<title>Dat Map tho</title>
<meta name="layout" content="main" />
<gvisualization:apiImport/>
<script type="text/javascript">
google.load('visualization', '1', { 'packages': ['map'] });
google.setOnLoadCallback(drawMap);
function drawMap() {
var data = google.visualization.arrayToDataTable([
['Lat', 'Long', 'Name'],
<g:each in="${places}" var="place" status="i">[${place.lat}, ${place.lon}, "${place.name }"],</g:each>
]);
var options = { showTip: true };
var map = new google.visualization.Map(document.getElementById('chart_div'));
map.draw(data, options);
};
</script>
</head>
<body>
<div id="chart_div"></div>
<br><br>
<a href="http://developers.google.com/chart/interactive/docs/gallery/map">Map Visualization Information</a>
</body>
</html>
关于Grails/Groovy 属性值引用未关闭 : Google Visualization API - data from Domain Class,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31654004/