簡體   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