Appmaker: How can I create and access global variables?

佐手、 提交于 2021-01-29 07:50:39

问题


I am trying to make a button which acts as a switch, enabling the visibility of a panel. I am running a client side script when the onClick event fires, which is the following:

function {
  if(app.datasources.global.item.hideshow===false)
    {
       *does one thing*
    }
    else if(app.datasources.global.item.hideshow===true)
    { 
       *does another*
    }
}

My problem is, that the global (which is the datasource).item seems to be a null according to the console error log. It seems like i am trying to access one property of a record from a database, but I would like to access and edit a property which is not attached to any database, it would be just a "global variable".

Maybe I haven't phrased it too well, but I hope somebody can help me out with this. Thank you in advance.


回答1:


There are a few ways you could do this. This link may help ontoggle Event. Another way I could see doing this would be using local storage.




回答2:


You can use a custom property for that. So in the page where you want to toggle the panel, create a custom property and perhaps call it panelVisibility. Then you can use the following logic on the onclick event handler of the button:

var visible = widget.root.properties.panelVisibility || false;
if(visible){
  //do someting
} else {
  //do other thing
}
widget.root.properties.panelVisiblity = !visible;


来源:https://stackoverflow.com/questions/58101720/appmaker-how-can-i-create-and-access-global-variables

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!