Search code examples
javascriptvariablesextjshidden

Ext js 6 read variable define


I need to use ext js and I have a newbie problem, I don't know how to read variables inside Ext.define.

this is my code:

Ext.define('AutoPrenotazioni.view.riepilogo.Riepilogo', {
   extend: 'Ext.tab.Panel',
   xtype: 'app-main',
   requires: [
      'Ext.MessageBox',
      'Ext.layout.Fit'
   ],
   controller: 'main',
   items: [
    {
        title: 'Home',
        layout: 'fit',
        items: [{
            xtype: 'mainlist'
        }]
    },{
        title: 'Prenota Auto'
    },{
        title: 'Auto Prenotate'
    },{
        title: 'Gestisci Parco Auto',
        hidden: function(){
           if(localStorage.getItem("Admin") == 'Si'){
             return false;
           }else{
              return true;
           }
        }
    }
],



listeners: {
    activeitemchange: function(homepnl, value, oldValue){
       console.log(value.title);
       return false;
    }
}

});

Main problem:

hidden: function(){
  if(localStorage.getItem("Admin") == 'Si'){
      return false;
  }else{
      return true;
  }
}

this is not working (but if I put hidden: true or false it works).

I tried with a global variable and I tried to set it inside Ext.onReady and if I use a console log inside the activeitemchange of listeners the global variable got the right value.


Solution

  • hidden expects a boolean, you are assigning a function which returns a boolean. I would try simply:

     hidden: localStorage.getItem("Admin") !== 'Si'