【发布时间】:2020-06-13 02:36:30
【问题描述】:
目前我成功地在数据表之外出现了一个下拉结果,但是如何将下拉列表移动到每个数据表行中?在我的情况下,在服务目录列中。我到处寻找,但没有达到我想要的。当前不应该出现外部数据表的下拉菜单。
HTML
<table id="bindNewServiceTable">
<thead>
<tr>
<th class="text-center">Admin Status</th>
<th class="text-center">Operate Status</th>
<th class="text-center">Service Catalogue</th>
<th class="text-center">Action</th>
</tr>
</thead>
</table>
<select id="dropdown">
<option></option>
</select>
JS
$('#bindNewServiceTable').DataTable({
ajax: {
url: url_bind,
crossDomain : true,
type : "POST",
cache : false,
dataType : "json",
contentType: "application/json",
dataSrc : "service"
},
columns: [
{ data : "admin_status" },
{ data : "operate_status" },
{ data : "id", "className": "text-center",
render: function(data){
return createSelect(data);
}
},
{ data : "example" },
],
});
function createSelect(id){
$.ajax ({
url: url_list_cat,
type : 'POST',
dataType : 'json',
data: id,
cache: false,
contentType: "application/json",
processData: true,
timeout: 10000,
success: function(response){
for (var i = 0; i < response.category.length; i++) {
$("#dropdown").append($("<option>", {
response: response.category[i].name,
text: response.category[i].name
}));
}
}
});
}
【问题讨论】:
标签: javascript html jquery datatables