Javascript 如何重新创建表';jQuery的内容是什么?
我想动态刷新表中的内容。这里的代码只启动但不重新加载表 内容存储在“data”对象中,其值来自rest调用。这项工作没有任何问题 我遇到的问题是,当我第二次加载另一个“data”myDataGrid()函数时,该函数不起作用。我怎样才能刷新它?我是否应该以某种方式破坏这个物体 这来自主要的js代码:Javascript 如何重新创建表';jQuery的内容是什么?,javascript,jquery,Javascript,Jquery,我想动态刷新表中的内容。这里的代码只启动但不重新加载表 内容存储在“data”对象中,其值来自rest调用。这项工作没有任何问题 我遇到的问题是,当我第二次加载另一个“data”myDataGrid()函数时,该函数不起作用。我怎样才能刷新它?我是否应该以某种方式破坏这个物体 这来自主要的js代码: $('#DataTables_Table_1_wrapper').html(""); $('table[data-table-name="dt-testCells"]').myDataGrid({
$('#DataTables_Table_1_wrapper').html("");
$('table[data-table-name="dt-testCells"]').myDataGrid({
'aoColumns': cols,
'aaData': data
});
创建表格:
MyDataGrid.prototype = {
constructor: MyDataGrid,
init: function(type, element, options) {
this.type = type;
this.$element = $(element);
this.name = this.$element.data('table-name');
this.settings = this.getOptions(options);
this.createTable(options);
},
createTable: function(options) {
// Init the datatable
this.$table = this.$element.dataTable(this.settings);
// Row Selection
this.$table.on('click', 'tbody tr', $.proxy(this.clicked, this));
}
我看到您正在使用DataTables(虽然这是一个要点,但您没有提到),它是为ajax调用和表刷新而设计的。查看文档中来自ajax的数据:什么不起作用?没有显示有关加载新文件的内容data@charlietfl数据已正确加载且位于“数据”对象中。它第一次正确地创建了表。但即使正确加载了数据对象,也不是第二次。我的理论是它第二次、第三次等不会进入myDataGrid({})内部。@JeremyThille我会检查的,谢谢。