简体   繁体   English

在数据表中填充自定义下拉框

[英]Populate a Custom drop down box in Data Table

I am trying to populate a drop-down box which I have created in the Data-Tables plug-in for JQuery. 我正在尝试填充一个在JQuery的数据表插件中创建的下拉框。 The code I have used is: 我使用的代码是:

var oTable = $('#reqAllQueriesTable')
.dataTable(
{
 "sDom": '<"H"<"tools">lfrt>',
});
$("div.tools").html('Organize by Teams: <select id="booking_status"><option value="">Teams</option><option value="team1">Team 1</option><option value="team2">Team 2</option></select>');

I want to replace the static contents of select in HTML by the content by a List of objects in my Java code. 我想用Java代码中的对象List将HTML中的select静态内容替换为内容。 Is this possible by replacing the existing code? 是否可以通过替换现有代码来实现? If yes, how can the Java object be used in this code. 如果是,那么如何在此代码中使用Java对象。 Please help. 请帮忙。

Got the answer. 得到了答案。 I pass a model attribute from my java code which calls the JSP: 我从调用JSP的Java代码中传递了模型属性:

model.addAttribute("userTeams",userTeams);

Then in jQuery Data Table, I overwrite the DOM to call a div named myTools : 然后在jQuery数据表中,我覆盖DOM来调用名为myToolsdiv

var oTable = $('#reqAllQueriesTable')
.dataTable(
{
 "sDom": '<"H"<"myTools">lfrt>',
});

The div which creates the drop-down list looks like: 创建下拉列表的div如下所示:

$("div.myTools").html('Organize by Teams: <select id="teams"><option value="">Team</option><c:forEach var="userTeams" items="${userProjectTeams}"><option value="${userTeams.teamId}" onClick="javascript:takeAction(this.value)"> ${userTeams.teamtName}</option></c:forEach></select>');

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM