简体   繁体   English

Bootstrap手风琴刷新设置

[英]Bootstrap Accordion Refresh Settings

I have a bootstrap accordion in my web app using the code found in the bootstrap documentation: 我的Web应用程序中有一个bootstrap手风琴,它使用bootstrap文档中的代码:

<div class="accordion" id="accordion2">
  <div class="accordion-group">
    <div class="accordion-heading">
      <a class="accordion-toggle" data-toggle="collapse" data-parent="#accordion2" href="#collapseOne">Section 1</a>
    </div>
    <div id="collapseOne" class="accordion-body collapse in">
      <div class="accordion-inner">
      </div>
    </div>
  </div>
  <div class="accordion-group">
    <div class="accordion-heading">
      <a class="accordion-toggle" data-toggle="collapse" data-parent="#accordion2" href="#collapseTwo">Section 2</a>
    </div>
    <div id="collapseTwo" class="accordion-body collapse">
      <div class="accordion-inner">
      </div>
    </div>
  </div>
</div>

In my application.html.erb file I have a line of code set to refresh the page every 30 seconds. 在我的application.html.erb文件中,设置了一行代码,每30秒刷新一次页面。

<meta http-equiv="refresh" content="30" >

When the page refreshes it always opens up with the first section open. 页面刷新时,它总是在打开第一部分的情况下打开。 Is there a way to refactor the code so when the page refreshes it will stay the way the page was before the refresh? 有没有一种方法可以重构代码,以便页面刷新时将保持刷新之前的状态?

Realized the solution is pretty simple, by changing this line of code: 通过更改以下代码行,实现解决方案非常简单:

<div id="collapseTwo" class="accordion-body collapse">

to this: 对此:

<div id="collapseTwo" class="accordion-body collapse in">

the section will stay open when the page is refreshed 页面刷新后,该部分将保持打开状态

There is, but it will be complex. 有,但是会很复杂。 The complexity lies in retaining the page state the user has created during their interactions. 复杂性在于保留用户在交互过程中创建的页面状态。

Each interaction which changes the state of the GUI is going to need to be tracked so that, after 30 seconds, when the page refreshes it will be clear what the current state is. 每次更改GUI状态的交互都需要进行跟踪,以便在30秒后页面刷新时,可以清楚地知道当前状态。

In order to maintain the state through the page load you are going to have to use local storage in order to save the data that you collected during the interactions. 为了通过页面加载保持状态,您将必须使用本地存储来保存在交互过程中收集的数据。

Implementing this feature as a whole will not be a trivial undertaking. 整体上实现此功能将不是一件容易的事。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM