在桌子中显示几张图片
我正在尝试使用Flays&试图在表中显示几张地图。胸腺。这意味着我必须以不同的方式命名每个地图容器,或者否则会遇到错误,因为具有此类名称的容器已经初始化。我设法使用Thymeleaf的标准表达语法进行了操作,到目前为止尚未获得误差,但地图没有显示。我正在使用这些表达式来命名“路由ID”之后,即数字字符串。 如果有人可以就我做错了什么提供一些建议,那将不胜感激。
<tbody>
<tr th:each="route: ${listRoutes}">
<form th:action="@{/delete_route}" method="get">
<td><input type="hidden" name ="routeID" th:value="${route.id}" class="form-control"></input> [[${route.id}]] </td>
<td><div th:id="${route.id}"></div>Map Container </td>
<td th:text="${route.owner.id}">Owner</td>
<td th:text="${route.participants}">Participants</td>
<td style="cursor:pointer"><input type="submit" value="Delete Route" class="btn btn-primary" /> </td>
<script th:inline="javascript">
var map = new L.map("[[${route.id}]]");
L.tileLayer('http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
attribution: 'Map data © <a href="http://openstreetmap.org">OpenStreetMap </a>',
maxZoom: 18
}).addTo(map);
L.control.scale().addTo(map);
var gpx = /*[[${route.directions}]]*/ "";
new L.GPX(gpx, {async: true}).on('loaded', function(e) {
map.fitBounds(e.target.getBounds());
}).addTo(map);
</script>
</form>
</tr>
</tbody>
I am trying to display several maps within a table, using Leaflet & Thymeleaf. This means that I have to name each map container differently or otherwise I get an error because a container with such name is already initialised. I managed to do it using Thymeleaf's standard expression syntax and got no erros so far but the maps are not displaying. I am using these expressions to name the map container's id after a 'route id' which is a numeric string.
if anybody could offer some advice on what am I doing wrong, it will be much appreciated.
<tbody>
<tr th:each="route: ${listRoutes}">
<form th:action="@{/delete_route}" method="get">
<td><input type="hidden" name ="routeID" th:value="${route.id}" class="form-control"></input> [[${route.id}]] </td>
<td><div th:id="${route.id}"></div>Map Container </td>
<td th:text="${route.owner.id}">Owner</td>
<td th:text="${route.participants}">Participants</td>
<td style="cursor:pointer"><input type="submit" value="Delete Route" class="btn btn-primary" /> </td>
<script th:inline="javascript">
var map = new L.map("[[${route.id}]]");
L.tileLayer('http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
attribution: 'Map data © <a href="http://openstreetmap.org">OpenStreetMap </a>',
maxZoom: 18
}).addTo(map);
L.control.scale().addTo(map);
var gpx = /*[[${route.directions}]]*/ "";
new L.GPX(gpx, {async: true}).on('loaded', function(e) {
map.fitBounds(e.target.getBounds());
}).addTo(map);
</script>
</form>
</tr>
</tbody>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
一些注释以扩展我的最后一个问题:
我假设有一个
路由
类(或类似的内容),如以下内容:该模型随后包含
list&lt; route&gt; listroutes
用于使用百里香。胸腺模板看起来像以下内容。
我简化了这一点以删除表单,并专注于整体结构&amp;数据处理:
现在,HTML表更简单。
&lt; script th:inline =“ javascript”&gt;
允许胸腺允许thymeleaf渲染list&lt; route&gt;
数据作为JavaScript对象的数组:之后,您,您可以根据需要构建每张地图。
(我实际上不需要使用
var maps = [];
- 我的评论的一部分是不正确的。)Some notes to expand on my last comment in the question:
I assume there is a
Route
class (or something similar), which looks like the following:The model then contains a
List<Route> listRoutes
for Thymeleaf to use.The Thymeleaf template will look something like the following.
I have simplified this to remove the form, and to just focus on the overall structure & processing of the data:
Now, the HTML table is much simpler.
The use of
<script th:inline="javascript">
allows Thymeleaf to render theList<Route>
data as an array of JavaScript objects:After that, you can build each map as needed.
(I did not actually need to use
var maps = [];
- that part of my comment was incorrect.)