简体   繁体   English

jQuery 数据表正在返回 html

[英]jQuery Datatables is returning html

I'm using jQuery DataTables for one project.我在一个项目中使用 jQuery DataTables。 I applied datatable to an existing table, as shown below:我将数据表应用于现有表,如下所示:

var table = '#datatable-1';
var dataTable = $(table).DataTable({
    'paging'      : true,
    'lengthChange': true,
    'searching'   : true,
    'ordering'    : true,
    'info'        : true,
    'autoWidth'   : false,
    select: {
        style: 'multi'
    }
});

Then I iterate over each row of the table, try to get the row content, but I obtained some HTML inside.然后我遍历表的每一行,尝试获取行内容,但我在里面获取了一些 HTML。

dataTable.rows({
    order: 'applied',
    page: 'all',
    search: 'applied',
    selected: true
}).every(function (rowIdx, tableLoop, rowLoop) {
    console.log(this.data());
});

这就像我的桌子看到的一样

And this is the result after I do a console.log(this.data()) .这是我执行console.log(this.data())后的结果。

Array [ "A &amp; B", "143 AVE", "", "AMAZON", "EU", "", "<textarea name="" rows="1"></textar…" ]

Anyone knows how to get the row content like is shown in the table?任何人都知道如何获取表中显示的行内容?

You can iterate over dummy elements to translate html entities by text() or extract form input values by val() (as I believe you want as well) :您可以遍历虚拟元素以通过text()转换 html 实体或通过val()提取表单输入值(我相信您也想要):

table.rows().every(function() {
  var data = this.data();
  data.forEach(function(d, index, arr) {
    d = $('<div>').html(d);
    arr[index] = d.val() || d.text()
  })
  console.log(data)
})

demo -> http://jsfiddle.net/ocL7xhzg/演示 -> http://jsfiddle.net/ocL7xhzg/

In your case the array would be logged out as在您的情况下,阵列将被注销为

Array [ "A & B", "143 AVE", "", "AMAZON", "EU", "", "" ]

You have an Array.你有一个数组。 You can get first record (A & B) with this.data()[0] .您可以使用this.data()[0]获得第一条记录(A 和 B)。 Increase array index for next values.增加下一个值的数组索引。

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

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