如何在Google App Maker中将回调附加到自定义确认对话框? [英] How to attach a callback to a custom confirmation dialog in Google App Maker?
问题描述
我正在Google App Maker中创建一个自定义确认对话框,并希望确认"按钮调用传入的函数.我没有在按钮小部件中看到"onclick"事件.有关如何执行此操作的任何建议?
I am creating a custom confirmation dialog in Google App Maker and would like the Confirm button to call a passed-in function. I don't see an "onclick" event in the button widget. Any suggestions on how to do this?
function confirmationDialog(msg, confirmFunction)
{
var desc = app.pageFragments.ConfirmationDialog.descendants;
var label = desc.Label;
var confirmButton = desc.Confirm;
label.text = msg;
confirmButton.onClick = confirmFunction; // does not work
app.showDialog(app.pageFragments.ConfirmationDialog);
}
谢谢
推荐答案
如果这容易一些,那就太好了,但是最好的选择是使用自定义属性(
It'd be great if this was a bit easier, but the best bet is to use Custom Properties (https://developers.google.com/appmaker/ui/viewfragments).
您可以设置类型为"Dynamic"的自定义属性,然后对其进行任何命名,例如"onConfirmCallback".然后,您可以在该自定义属性上设置功能:
You can set up a custom property of type "Dynamic" and call it anything, take "onConfirmCallback", for example. Then you can set the function on that custom property:
调用对话框的代码:
app.pageFragments.ConfirmationDialog.properties.onConfirmCallback = function(param) {
alert(param);
};
app.showDialog(app.pageFragments.ConfirmationDialog);
然后在onClick中单击关闭按钮:
And then in the onClick for the close button:
app.pageFragments.ConfirmationDialog.properties.onConfirmCallback("hi");
app.closeDialog();
还请注意,使用自定义属性,可以比示例中的标签设置方法更好一些.
Also note that there are slightly better ways to set up labels than in your example, also using custom properties.
为要自定义的任何窗口小部件属性创建自定义属性,然后将这些自定义属性(@ properties.propertyName)绑定到窗口小部件属性.例如,您可能具有一个confirmText属性,其确认按钮的文本属性是boudn到@ properties.confirmText.
Create custom properties for any widget properties you want to customize, and then bind those custom properties (@properties.propertyName) to the widget property. For example you might have a confirmText property, with the confirm buttons text property boudn to @properties.confirmText.
然后,当您调用对话框时,您只需设置这些自定义属性即可.使用所有属性,快速修改示例代码:
Then when you invoke your dialog, you can just set those custom properties. Quick modification of your example code using properties for everything:
function confirmationDialog(msg, confirmFunction)
{
var properties = app.pageFragments.ConfirmationDialog.properties;
properties.text = msg;
properties.confirmCallback = confirmFunction;
app.showDialog(app.pageFragments.ConfirmationDialog);
}
这篇关于如何在Google App Maker中将回调附加到自定义确认对话框?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!