【问题标题】:datatables dropdown combobox数据表下拉组合框
【发布时间】:2017-07-17 23:00:05
【问题描述】:

我正在使用来自https://datatables.net 的数据表。 数据表上的一列有一个下拉组合框作为单元格数据。 当我按下按钮时,我需要获取所选行内组合框的所选值。

$.each($("#prize_selector tr.selected"), function () {
var row = prizes_table.row(this).data();
row[3].$('select').options[row[3].$('select').selectedIndex].id; 
[...]
});

但没有成功。如何在不遍历表格上的所有输入选择的情况下访问单元格内的 DOM 选择? (有很多)。

edit控制台抛出 row[3].$ is not a function

【问题讨论】:

  • 请制作一个 JSFiddle(或类似的)来说明您的用例。
  • 我是来加小提琴的,不过Gyrocode.com的解决方案正是我所需要的。

标签: javascript jquery datatables


【解决方案1】:

我假设您正在使用 Select 扩展来选择行。

以下是访问每个选定行的select 元素的正确方法:

table.rows({ selected: true }).every(function(){
   var $select = table.$('select', this.node());
   var $option = table.$('select option:selected', this.node());

   console.log($select.val(), $option);
});

有关代码和演示,请参阅this example

【讨论】:

  • 这正是我需要的,不知道我们可以按选项过滤:选择。谢谢!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-02-20
  • 1970-01-01
  • 1970-01-01
  • 2014-05-01
  • 1970-01-01
相关资源
最近更新 更多