繁体   English   中英

如何使用自动完成的Spring MVC从JSTL中的列表中获取数据

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM