问题
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