[英]Get the selected value in dropdown in a particular column of datatable
I am trying to get the value of selected element in a dropdown in a column of datatable. 我试图在数据表的列中的下拉列表中获取选定元素的值。 Following is my code :
以下是我的代码:
function getstate(item) {
var rows = $("#content_objects_table").dataTable().fnGetNodes();
for(var i=0;i<rows.length;i++)
{
// Get HTML of 3rd column (for example)
console.log("item:"+item+" id:"+$(rows[i]).find("td:eq(1)").html());
if($(rows[i]).find("td:eq(1)").html()==item){
console.log($(rows[i]).find("td:eq(4)").div.select.data-state);
return ($(rows[i]).find("td:eq(4)").html());
}
}
};
So far I am able to get the value of column having the dropdown. 到目前为止,我已经能够获得具有下拉列表的列的值。 So I am getting a div like below:
所以我得到一个像下面的div:
<div class="selectorContainer assemblyCompleted" style="padding-left: 15px;">
<select class="states" style="width: 150px;" data-objectid="Scorm123" data-state="ready-for-publishing">
<option value="ready-for-publishing">Ready for Publishing</option>
<option value="published">Published</option>
<option value="rework">Rework</option>
</select>
</div>
How to get the value of selected option which is the value of data-state ie here data-state is "ready-for-publishing" and the value corresponding to it is Ready for Publishing. 如何获取所选选项的值,即数据状态的值,即此处的数据状态为“准备发布”,并且与之相对应的值为“准备发布”。
Try this 尝试这个
/* cache row so don't keep creating new object*/
var $row=$(rows[i]);
if($row.find("td:eq(1)").html()==item){
var state=$row.find("td:eq(4) select.states").data('state');
var optionText=$row.find('option[value="'+state+'"]').text();
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.