以form:options形式添加数据属性,即在options.tag中 [英] Adding data attribute in form:options, i.e., in options.tag

查看:500
本文介绍了以form:options形式添加数据属性,即在options.tag中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在pageContext中有一个对象列表,我希望它的某些属性在select的option标记的data属性中.

I have a list of objects in the pageContext and I want some of it's attribute in the data attribute of the option tag of select.

下面是jsp代码:

<form:select class="required chzn_a" disabled="${view}" path="one.id" id="one">
    <form:option value="">Select</form:option>
    <form:options items="${objectList}" itemValue="id" itemLabel="name"/>
</form:select>

我想要以下内容:

但是,下面是我得到的:

However, below is what I am getting :

推荐答案

据我所知,form:options标记不支持这样的自定义.相反,您可以自己遍历选项:

As far as I know the form:options tag does not support customization like this. Instead you can loop through the options yourself like this:

<form:select class="required chzn_a" disabled="${view}" path="one.id" id="one">
    <form:option value="">Select</form:option>

    <c:forEach items="${objectList}" var="objectListEntry">
        <form:option value="${objectListEntry.id}" data-code="${objectListEntry.code}">${objectListEntry.name}</form:option>
    </c:forEach>
</form:select>

spring表单标签实现了DynamicAttributes接口,并且所有未在tld中明确定义的属性都添加到了生成的标签中.

The spring form tags implements the DynamicAttributes interface and all attributes not explicitly defined in the tld are added to the generated tag.

这篇关于以form:options形式添加数据属性,即在options.tag中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆