我正在做一个项目,当用户点击他希望从中查看信息的项目时,我需要在谷歌地图小地图旁边显示数据。
基本上它是这样工作的:
- 用户单击他希望查看有关信息的标签
- 浏览器使用 jQuery 和 Handlebars 将单独的表格附加到屏幕的一侧,其中应该有:
- 显示信息来源位置的 Google 地图实例
- 资料
虽然不知何故我无法让 JS + jQuery + Handlebars 组合工作。我知道我需要创建一个帮助程序来在 Handlebars 模板中执行 JavaScript 代码,但是以某种方式在 HB 模板的表中添加一个 Google Maps 实例不起作用。
这是我目前正在处理的代码。谢谢你的帮助!
模板文件:
<script id="entry-template" type="text/x-handlebars-template">
<section class="Info" id={{id}}>
<header class="InfoHeader small" onclick="collapseInfobox(this)">
<p class=""></p>
</header>
<article class="hidden">
<table class="Analyses" border="1">
<tr>
<td class="minimap"><div id="minimap_1_{{id}}" class="minimap">{{miniMap_1 context}}</div></td>
<td class="graph"><div>{{ graph_1 }}</div></td>
</tr>
</table>
</article>
</section>
</script>
<script type="text/javascript">
var HTMLsource = $("#entry-template").html();
var HTMLtemplate = Handlebars.compile(HTMLsource);
</script>
JavaScript 代码:
function addInfo(id, start, end) {
var context = {
id: id,
};
Handlebars.registerHelper('miniMap_1', function(data) {
var minimapOptions = {
disableDefaultUI: true,
center: new google.maps.LatLng(_Coords.lat, _Coords.lon),
zoom: 13,
};
var minimap1 = new google.maps.Map(document.getElementById(this), minimapOptions);
});
// contentArea is a div section in the page to which the info div should be appended
$("#contentArea").append(HTMLtemplate(context));
}