JSP:
<form:select path="owner" id="funding-owner" class="funding-owner">
<c:forEach items="${itemList}" var="obj">
<form:option value="${obj.value}" data-street="${obj.street}"> ${obj.title} </form:option>
</c:forEach>
</form:select>
HTML输出:
<select id="funding-owner" class="funding-owner">
<option value="-1" data-street="100 First st">Waqas Ahmed</option>
<option value="0" data-street="5881 Spring Rock Circle">Abdul Kareem</option>
</select>
问题:
我想在select选项中添加多个data-*
属性,而不只是一个属性。
<select id="funding-owner" class="funding-owner">
<option value="1" data-street="100 First st" data-zip="44329" data-city="Columbus" data-state="OH">Waqas Ahmed</option>
<option value="0" data-street="1000 NS Secon" data-zip="12345" data-city="Fairfield" data-state="NY">Abdul Kareem</option>
</select>
我怎样才能在JSP中这样做? (我可以使用Spring 3标签)
答案 0 :(得分:1)
我已经找到了解决方案。在后端,我使用HashMap存储密钥对值。在JSP中,我通过引用我的基础obj指向了关键,它对我很有用。
<form:select path="owner" id="funding-owner" class="funding-owner">
<c:forEach items="${itemList}" var="obj">
<form:option value="${obj.value}" data-street="${obj.data.street}" data-city="${obj.data.city}" data-state="${obj.data.state}" data-zipcode="${obj.data.zipCode}"> ${obj.title} </form:option>
</c:forEach>
data-street="${obj.data.street}"
数据 =我的HashMap的getter / setter
street =我的HashMap中的键(EL将打印相应的值)
多数民众赞成。
答案 1 :(得分:0)
试试这个
<select name="owner" id="funding-owner" class="funding-owner">
<c:forEach items="${itemList}" var="obj">
<option value="${obj.value}" data-street="${obj.street}"> ${obj.title} </option>
</c:forEach>
</select>