2017-02-07 106 views
1

我正在使用引导表来显示来自我的MongoDB的数据,使用mongoid查询。我想每隔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 

感谢您的帮助!

回答

0

我想你删除表并重新创建:

setInterval(function(){ 
    $('#table').remove(); 
    $('#Table_Parent').append(Table_Html); 
}, 5000); 
0

我认为你需要做两个。您需要使用ajax从服务器获取数据,然后将其重新加载到数据表中。

只刷新数据表将重新加载数据,你有什么你的HTML,但你需要刷新,因为它会重新加载chaged数据。

为@Farzin坎兹代码,在设定的时间内而外使Ajax调用并与服务器数据

setInterval(function(){ 
    $.ajax(
    ... 
    success(response) { 
     Table_Html = resopnse 
    } 
    ) 
    $('#table').remove(); 
    $('#Table_Parent').append(Table_Html); 
}, 5000); 
+0

我想我看到你在做什么重装,但我不能确定如何将其纳入我的代码。我能够拼凑出以下JavaScript,它适用于我所需要的,尽管不像ajax调用那么专业。 ()函数(){ location.reload(); },60 * 1000); – user2843365