当我在我的react应用程序中执行一些操作时,例如,更新或删除,数据表不能运行,数据表只有在刷新页面时才运行--如何使它自动刷新?
//Datatable Modules
import "datatables.net-dt/js/dataTables.dataTables"
import "datatables.net-dt/css/jquery.dataTables.min.css"
import $ from 'jquery';
import { useEffect } from "react";
//initialize datatable
$(document).ready(function () {
setTimeout(function(){
$('#example').DataTable();
} ,100);
});
useEffect(() => {
init();
},[])
const init = () => {
employeeService.getAll()
.then(response => {
setEmployees(response.data);
})
.catch(error => {
console.log('Something wrong', error);
})
}返回容器
<table id="example" className="table table-bordered table-striped">
...
</table>发布于 2022-05-08 17:00:03
您正在寻找的东西需要使用实时数据更新,您可以使用本机WebSockets API,或者使用更简单的api (如Socket.IO )在客户端和服务器之间建立连接(发射/接收)并更新表数据.学习WebSockets祝你好运!
https://stackoverflow.com/questions/72163255
复制相似问题