gpt4 book ai didi

javascript - 数据表:DataTables_selected

转载 作者:行者123 更新时间:2023-12-03 03:58:13 24 4
gpt4 key购买 nike

我有一个 SpringBoot 应用程序我定义了一个数据表 1.10.15,我想在提交后保留所选行。这是我的 Thymeleaf 模板中的代码

<script th:inline="javascript">
/*<![CDATA[*/

$(document).ready(function() {


$('#deviceEventTable').dataTable( {
order: [[ 0, "desc" ]],
select: true,
bLengthChange: false,
stateSave: true,
pageLength: 20,
initComplete: function() {
var api = this.api();

if (localStorage.getItem( 'DataTables_selected' )!=null && localStorage.getItem( 'DataTables_selected' ) != 'undefined') {
var selected = localStorage.getItem( 'DataTables_selected' ).split(',');
var selected = '0';
selected.forEach(function(s) {
api.row(s).select();
})
}

}
});


table.on('select.dt deselect.dt', function() {
localStorage.setItem( 'DataTables_selected', table.rows( { selected: true }).toArray() )
})
} );

/*]]>*/
</script>

但是该行未被选择,而是出现以下错误:

jquery.min.js:2 Uncaught ReferenceError: table is not defined
at HTMLDocument.<anonymous> (1:473)
at j (jquery.min.js:2)
at k (jquery.min.js:2)

最佳答案

这会有所帮助

 $(document).ready(function() {


table = $('#deviceEventTable').dataTable( {
order: [[ 0, "desc" ]],
select: true,
bLengthChange: false,
stateSave: true,
pageLength: 20,
initComplete: function() {
var api = this.api();

if (localStorage.getItem( 'DataTables_selected' )!=null && localStorage.getItem( 'DataTables_selected' ) != 'undefined') {
var selected = localStorage.getItem( 'DataTables_selected' ).split(',');
var selected = '0';
selected.forEach(function(s) {
api.row(s).select();
})
}

}
});

table.on....
.....

关于javascript - 数据表:DataTables_selected,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44846418/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com