Leave a read menu with treeview active after page re-load

Asked

Viewed 247 times

0

I have a menu on a Sidebar using <li> and <ul>, when I click on any page is updated, because I use a link <a> in my.

i am using the following javasscript to update the active menu :

    $('li').each(function () {
    if (window.location.href.indexOf($(this).find('a:first').attr('href')) > -1) {
        $(this).addClass('active').siblings().removeClass('active');
    }
});

This template works well for menus <li> but when I have a

like this :

<li class="treeview">
    <a href="#">
        <i class="fa fa-group" style="color:#4b676f"></i> <span>Partners</span>
        <span class="pull-right-container">
            <i class="fa fa-angle-left pull-right" ></i>
        </span>
    </a>
    <ul class="treeview-menu">
        <li>
            <a href="@Url.Action("Index", "Parceiro" , new { Area="Unidade" })"><i class="fa fa-list" style="color:#4b676f"></i> <span>List Partners</span></a>
        </li>
        <li>
            <a href="@Url.Action("NovoParceiro", "Parceiro" , new { Area="Unidade" })"><i class="fa fa-plus" style="color:#4b676f"></i> <span>Register a new Partner</span></a>
        </li>
    </ul>
</li> 

he does not change the <li> back to the pattern, I would like to know how to leave this item as active. I saw several answers but could not understand any.

just like this my page:

 <li style="margin-top:45px;font:normal" class="active"><a [email protected]("Index", "Dashboard" , new { Area="Unidade" })><i class="fa fa-bar-chart" style="color:#4b676f"></i> Statics and Reports</a></li>
    <li>
        <a href="@Url.Action("Index", "Informacoes" , new {Area="Unidade" })"><i class="fa fa-home" style="color:#4b676f" ></i> <span> Falcon Company</span></a>
    </li>
    <li>
        <a href="@Url.Action("Index", "Agendamento" , new {PaginaAtual = 0 , Area="Unidade" })"><i class="fa fa-calendar" style="color:#4b676f"></i> <span>Jobs Schedule</span></a>
    </li>
    <li class="treeview">
        <a href="#">
            <i class="fa fa-stethoscope" style="color:#4b676f"></i> <span>Employee</span>
            <span class="pull-right-container">
                <i class="fa fa-angle-left pull-right"></i>
            </span>
        </a>
        <ul class="treeview-menu">
            <li><a [email protected]("Index", "Profissional" , new {PaginaAtual = 0 , Area="Unidade" })><i class="fa fa-list" style="color:#4b676f"></i> List Employees</a></li>
            <li><a [email protected]("NovoProfissional", "Profissional" , new { Area="Unidade" })><i class="fa fa-plus" style="color:#4b676f"></i>Register a new Employee</a></li>

        </ul>
    </li>
    <li class="treeview">
        <a href="#">
            <img src="~/Content/imagens/IconesDashboard/dashboard.png" style="height:13px;margin-right:9px"> <span>Client</span>
            <span class="pull-right-container">
                <i class="fa fa-angle-left pull-right"></i>
            </span>
        </a>
        <ul class="treeview-menu">
            <li><a [email protected]("Index", "Empresa" , new {PaginaAtual = 0 , Area="Unidade" })> Client List</a>
            <li><a [email protected]("NovaEmpresa", "Empresa" , new { Area="Unidade" })>Register a new Client</a></li>
            @*<li><a [email protected]("Index", "Dashboard" , new { Area="Unidade" })> Outras Informacoes</a></li>*@
        </ul>
    </li>
    <li class="treeview">
        <a href="#">
            <i class="fa fa-group" style="color:#4b676f"></i> <span>Partners</span>
            <span class="pull-right-container">
                <i class="fa fa-angle-left pull-right" ></i>
            </span>
        </a>
        <ul class="treeview-menu">
            <li>
                <a href="@Url.Action("Index", "Parceiro" , new { Area="Unidade" })"> <span>List Partners</span></a>
            </li>
            <li>
                <a href="@Url.Action("NovoParceiro", "Parceiro" , new { Area="Unidade" })"></i> <span>Register a new Partner</span></a>
            </li>
        </ul>
    </li> 

1 answer

0


You will need to record this information in the customer’s browser (either by cookies, or by Google, or in any way you think is acceptable) and when you load the page check if this preference exists and if so, then select the value that is equal to the recorded information.

  • Which way would you indicate me to do this ? have some example ? I will be looking over the issues cited , thank you very much.

  • The strange thing is that it works perfectly if the menu has only 1 level, but when it has sublevels it does not work.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.