1

我正在使用一些 javascript 让用户在主索引页面上折叠并隐藏 8 个不同的表。

$(".priority-header").click ->   //on click
  $(this).next().toggle()        // Hide Table
  $(this).toggleClass('closed')  //Assign class "closed"

我希望能够保存用户的配置,以便当他们隐藏或显示表格时,下次导航到主页时它会保持隐藏或显示。使用 rails 保存此用户配置的最佳方法是什么。我正在考虑使用会话变量或 cookie,但不确定如何执行此操作。这不一定是数据库保存,会话或 cookie 就可以了。

4

2 回答 2

2

您可以使用用户 localStorage 来存储用户首选项。这要求用户使用现代的、兼容 HTML5 的浏览器。

//When the user click the "hide" button
localStorage['hidePreference'] = 'hidden';

...

//When the page loads
if(localstorage['hidePreference'] === 'hidden') {
    //Hide the stuff with jQuery
}
于 2013-05-14T14:48:38.693 回答
2

Since you are already using jQuery, you could use the jquery-cookie plugin. There is no browser restriction.

You can replace to calls to localStorage of @pdegand59 's solution to $.cookie['hidePreference'].

于 2013-05-14T15:01:55.520 回答