简体   繁体   中英

How can show and hide a <li> inside the panel?

I have an app that has a login page. In order to login the user has the permission to see two voice inside the panel (if user is admin). If user is not admin I'd like to not display this voices. My problem is how to hide and show its. I have the panel inside index.html.This are the voice that I'd like to display or not in order users permission.

            <li id="company" display="none">
                    <a href="/aziende/" class="panel-close" >
                        <div class="item-content">
                            <div class="item-media">
                                <i class="f7-icons ios-only">home</i>
                                <i class="material-icons md-only">home</i>
                            </div>
                            <div class="item-inner">
                                <div class="item-title">Company</div>
                            </div>
                        </div>
                    </a>    
                </li>

                <li id="users" display="none">
                    <a href="/users/" class="panel-close">
                        <div class="item-content">
                            <div class="item-media">
                                <i class="f7-icons ios-only">person</i>
                                <i class="material-icons md-only">account_circle</i>
                            </div>
                            <div class="item-inner">
                                <div class="item-title">Users</div>
                            </div>
                        </div>
                    </a>
                </li>

this is app.js

     {
        name: 'login',
        path: '/login/',
        url: './pages/login.html',
        on:{ 
                pageInit: function(){

                    app.navbar.hide('.navbar');
                    if(user.checkPermission() == 'true'){
                        app.router.navigate('/home/');

                        }
                    }
            },
    },
    {
        name: 'home',
        path: '/home/',
        url: './pages/home.html',
        on: {
            pageInit:   function(e, page) {

                            app.navbar.show('.navbar');
                             if(user.checkPermission() == 'true'){
                                addVoicesToNavbar();

                             }
                            }                                   
                            page.router.clearPreviousHistory();
                        }

        },
    }

this method said me that Cannot set property 'display' of null

  function addVoicesToNavbar(){
      document.getElementById("company").display = "block";
      document.getElementById("users").display = "block";

   }

display is not a valid html attribute, it is a CSS property.

So setting display="none" on your <li> in the example doesn't do anything.

Instead in your markup you need to set an inline CSS style like this to initially hide the element:

<li id="users" style="display:none;">

And in your function change that inline CSS style like this to show it:

document.getElementById("users").style.display = "block";

Here is an example of what you could do:

 function addVoicesToNavbar(){
      companyElement = document.getElementById("company");
      companyElement.style.display = "block";

      ...
   }

Hope it helps!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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