簡體   English   中英

如何從清單中獲得價值 <Bean> 使用Spring的jQuery對象?

[英]How to get Value from List<Bean> object in Jquery using Spring?

在我的Spring Application中有一個Bean。

    public class SampleBean{
      private String id;
      private String name;
      private String marks;
      --------
      --------
}

和我的另一個Service bean的Crating屬性類似。

List<SampleBean> list = new Array<SampleBean>();
//Setter and getters

並在我的Controller類中設置一些值以list

現在我的jsp我正在使用jQuery獲取這些值。

<c:set var="modalAttributeName"value="MODEL1" />
<c:set var="modalAttribute"value="${requestScope[modalAttributeName]}" />
  <form:select class="select_box" path="country" id="country">
     <form:options items="${modalAttribute.list}" />
  </form:select>

它顯示了整個Bean名稱,例如SampleBean@0

但是我只想在此“選擇”框中僅提供SampleBeanname

那么如何使用Jquery顯示名稱?

EDIT

我正在嘗試這樣,但顯示為空框。

     <form:select class="select_box" path="country" id="country">
        <c:forEach items="${modalAttribute.list}" var="result">
            <form:options item="${result.name}" />
        </c:forEach>
    </form:select>

可以從控制程序將列表呈現為JSOn並將其捕獲到進行ajax調用的Java腳本代碼中,從而使其更易於在jquery中使用

將此列表添加到模型屬性映射。 我假設您已經將模型映射傳遞到控制器方法中。 因此,例如:

model.put("list", list);

如果沒有將模型映射傳遞到您的方法,則只需另一個參數: Map<String, Object> model

然后在您的JSP中:

 <form:select class="select_box" path="country" id="country">
    <c:forEach items="${list}" var="result">
        <form:option value="${result.name}">
            <c:out value="${result.name}"/>
        </form:option>
    </c:forEach>
</form:select>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM