I have a list of items, let's say types. I can display a <select> tag like so:
<form:select path="typeId" items="${types}" itemLabel="name" itemValue="typeId"/>
I would like to add the description property from the Type object to a data- attribute on the <option> tag for use with javascript.
This doesn't work, but just to provide an illustration:
<form:select path="typeId"/>
<form:options items="${types}" itemLabel="name" itemValue="typeId" data-description="description"/>
</form:select>
How can I gain access to the description property to populate the dat开发者_开发问答a-description attribute?
You need to implement your own tag (may on base of form:options), but as far as I know there is no concept of extending tags. (sorry)
data-description is not a valid attribute according to the TLD, so any custom attribute will potentially throw exception.
You can:
- Build select and options using standard tag lib using c:forEach OR
- Repurpose existing unused attribute for JavaScript. May be "title" attribute?
加载中,请稍侯......
精彩评论