Dynamically Bind Data source to app maker popup

江枫思渺然 提交于 2021-02-08 05:07:20

问题


I need to have a generic "Delete confirmation" pop up and dynamically bind data source to the pop up using event fired before pop-up is appeared.

Popup will be appeared on clicking the delete icon on "Location" Page (screenshot bellow). I need to set the data source of the popup at the same time. (when user click on this delete icon) and record has to be deleted when user click on "Delete" button on the popup.

This is the code I have currently for the onclick event of the delete icon above

app.popups.ItemDeleteConfirmationDialog.descendants.Content.datasource = widget.datasource;
app.popups.ItemDeleteConfirmationDialog.descendants.ConfirmButton.datasource = widget.datasource;
app.popups.ItemDeleteConfirmationDialog.visible=true;

And this is what I have for the onClick button of the pop-up

widget.datasource.deleteItem();

Please help me to get this resolved. Thank you.


回答1:


The following was suggested by someone from the App Maker team at Google:

In your Confirmation Popup set a custom property of type Dynamic. For the purposes of this example call the property CallbackFn.

For the onClick event of your ConfirmButton in the popup set the following client script:

if (typeof widget.root.properties.CallbackFn === 'function') {
  widget.root.properties.CallbackFn();
}
widget.root.visible = false;

For the delete button in your datasource table set the following client script:

deleteItem(widget.datasource);

In your scripts section add a client script or insert the following function under an existing client script:

function deleteItem(datasource) {
  var popup = app.popups.ItemDeleteConfirmationDialog;

  popup.properties.CallbackFn = function() {
    datasource.deleteItem();
  };

  popup.visible = true;
}

Since your delete button in your table is within a table row, you may need to change the function variable that you pass to the deleteItem() function as follows:

deleteItem(widget.parent.parent.datasource);

If this doesn't work let me know. I have this set up in my own application with much more complex logic and I pass multiple variables in some cases to my deleteItem() function and it works great.



来源:https://stackoverflow.com/questions/53115362/dynamically-bind-data-source-to-app-maker-popup

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