[英]How to get data from List in JSTL with autocomplete spring mvc
我正在使用JSTL和Jquery将数据导入自动完成功能,数据列表将从Spring MVC中的List获取
我的动作:
List<Map> mapList = googleMapLocationService.getAllGoogleMapLocations();
model.put("mapList", mapList);
jQuery的/ JSP:
<script>
$( function() {
var availableTags =
<c:forEach items="${mapList}" var="map">
[
"<c:out value="${map.address}"/>"
];
</c:forEach>
$( "#tags" ).autocomplete({
source: availableTags
});
} );
<div style="width:320px ;margin-left: -38px; margin-top: -24px">
<input id="tags" path="tags" />
</div>
更新:(尝试替换“地址”为“ id”)
<script>
$( function() {
var availableTags = []
<c:forEach items="${mapList}" var="map">
availableTags.push("<c:out value="'${map.id}', "/>");
</c:forEach>
$( "#tags" ).autocomplete({
source: availableTags
});
} );
结果:
当我输入任何“关键字”时,似乎无法列出自动填充内容
我该如何解决该问题? 非常感谢 !
此代码生成javascript数组结构。 尝试检查一下。
<script>
$( function() {
var availableTags =
<c:forEach items="${mapList}" var="map" varStatus="totalCount">
[
<c:out value="'${map.address}'">
</c:out>
<c:if test="${totalCount.count lt fn:length(mapList)}">
<c:out value=",">
</c:out>
</c:if>
];
</c:forEach>
$( "#tags" ).autocomplete({
source: availableTags
});
} );
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.