在浏览器存储中保存树视图菜单的状态 [英] Saving state of treeview menu in browser storage

查看:30
本文介绍了在浏览器存储中保存树视图菜单的状态的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用 javascript 构建的 html 页面.现在我希望页面记住"已打开哪个树视图.当菜单关闭时,类 'testclosed' 被添加到 div 中.

I've got an html page that is built up using javascript. Now I want the page to "remember" which treeview has been opened. When the menu is closed the class 'testclosed' is added to the div.

场景:用户打开菜单,然后点击一个按钮来完成他的任务.在此之后,用户必须返回此页面并检查所有内容是否正确填写.然后用户必须再次找到他的项目.因此,我想让浏览器记住他离开页面时打开了哪个项目

Scenario: The user opens the menu and then clicks on a button to complete his task. After this the user must come back to this page and check if everything is filled properly. THe user then has to find his item again. Therefore, I want the browser to remember which item was open when he left the page

我已经在这个问题中找到了部分答案在这里问.我似乎唯一找不到的是如何进行检查,以便我可以将其保存在浏览器存储中

I have found part of the answer in this question already asked here.The only thing that I cannot seem to find is how to do the check so that I can save it in the browser storage

这是切换菜单(打开和关闭)的代码

Here is the code that toggles the menu(open and closed)

$('.testlevel2').click(function () {
    var group = $(this).attr('group');
    var groupval = $(this).attr('groupvalue');
    $("div").find("[" + group + "='" + groupval + "']").toggleClass("testclosed");
});
 return "</div>";

任何帮助将不胜感激.谢谢

Any help would be appreciated. Thank you

推荐答案

思南有正确的想法,让我走上了正确的轨道.这是我最终想出的答案.

Sinan had the right idea and set me on the right track. This is the answer I eventually came up with.

当项目关闭时添加testclosed"类.这已经是问题中的情况.

The "testclosed" class is added when the item is closed. This was already the case as in the question.

我在下面的 save() 函数中所做的是将 localStorage 设置为 true 如果找到类.

What I've done in the save() function below is set the localStorage to true if the class is found.

在 load() 函数中,我获取 localStorage 项,如果它设置为 true,则删除类testclosed".

In the load() function I then get the localStorage item and if it is set to true, the class "testclosed" is removed.

$(document).ready(load);



function save() {
   var saveDiv = document.getElementsByClassName("testclosed"); 
   if (saveDiv) {

      localStorage.setItem("isMenuOpen", true);

   }

}

function load() {
   var isMenuOpen = localStorage.getItem("isMenuOpen");
   if (isMenuOpen) {

      $(".testitem").removeClass("testclosed");

   }

}

这篇关于在浏览器存储中保存树视图菜单的状态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆