我正在使用 bootstrap 表通过 mongoid 查询来显示来自 MongoDB 的数据。我想每隔 5 分钟刷新一次表。我已阅读文档,但作为 Javascript 新手,我不确定如何实现此目的 - 是使用 Ajax 调用还是仅使用 setTimeout() 函数等。
这是我的表代码:
<table id="table" data-show-refresh="true" data-row-style="rowStyle" data-toggle="table" data-url="http://maccdx160121:4567/api/v1/currentsat*">
<thead>
<tr>
<th data-field="initials">Initials</th>
<th data-cell-style="cellStyle" data-field="sector">Sector</th>
<th data-field="cjs">CJS</th>
</tr>
</thead>
</table>
这是我的 Mongoid 查询,如果有帮助的话:
get '/currentsat*' do
#SatTransaction.where( current: true, :initials.ne => nil, :position.in => ["RDR", "SPVR", "OJI"] ).to_json
SatTransaction.where( current: true, :shift_duration.ne => 0, ).and(SatTransaction.or({:position.in => ["SPVR", "RDR", "OJI"]},{sector: "BREAK"}).selector).to_json
end
end
before do
cache_control :no_cache
end
def with_captured_stdout
old_stdout = $stdout
$stdout = StringIO.new('', 'w')
yield
$stdout.string
ensure
$stdout = old_stdout
end
感谢您的帮助!!
最佳答案
我认为您删除了该表并重新创建了它:
setInterval(function(){
$('#table').remove();
$('#Table_Parent').append(Table_Html);
}, 5000);
关于javascript - 引导表刷新,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42100051/