【问题标题】:Bootstrap Table refresh引导表刷新
【发布时间】:2017-06-25 07:11:08
【问题描述】:

我正在使用引导表显示来自我的 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

感谢您的帮助!!

【问题讨论】:

    标签: javascript ajax bootstrap-table


    【解决方案1】:

    我认为您删除了表格并重新创建:

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

    【讨论】:

      【解决方案2】:

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

      仅刷新数据表只会重新加载您在 html 中的数据,但您需要刷新,因为它会重新加载已更改的数据。

      作为@Farzin Kanzi 代码,在设置的超时时间内进行ajax 调用并重新加载服务器数据

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

      【讨论】:

      • 我想我明白你在做什么,但我不确定如何将它合并到我的代码中。我能够拼凑以下适用于我需要的 javascript,尽管它不如 ajax 调用那么专业。
      猜你喜欢
      • 2016-05-21
      • 2015-01-26
      • 2020-06-01
      • 1970-01-01
      • 1970-01-01
      • 2017-04-13
      • 1970-01-01
      • 2018-12-30
      • 2015-11-14
      相关资源
      最近更新 更多