2017-02-07 1 views
1

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 

감사합니다!

답변

0

나는 테이블을 제거하고이를 다시 생각한다 :

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

난 당신이 모두를 할 필요가 있다고 생각합니다. ajax를 사용하여 서버에서 데이터를 가져 와서 데이터 테이블에 다시로드해야합니다.

데이터 테이블을 새로 고치는 것만으로 html에있는 데이터를 다시로드하지만 chaged 데이터를 다시로드하기 때문에 새로 고침해야합니다.

는 @Farzin 칸지 코드로, 설정된 시간 안에 밖으로 아약스 전화를하고

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

나는 당신이 무엇을하고 있는지 볼 생각 서버 데이터를 다시로드,하지만 난 내 코드에 통합하는 방법을 확실하지 오전 . Ajax 호출처럼 전문적이지는 않지만 필요한 자바 스크립트를 함께 만들 수있었습니다. user2843365

관련 문제