使用来自页面参数的查询过滤器处理浏览器刷新

时间:2019-05-14 16:31:46

标签: google-app-maker

我有两个数据源

  1. 资产

  2. 位置

资产与位置具有一对多的关系

资产具有一个查询构建器数据源AssetLocFiltered,该数据源设置为以下内容:

ParentLocationKey =:ParentLocationKey

ParentLocationKey是位置表的关系字段。

在主页上选择一个位置,然后单击将位置ID传递到ShopPageDemo页面上的参数的按钮。使用以下代码

app.pages.ShopPageDemo.properties.ParentLocationKey = 
widget.datasource.item.Id;
console.log(widget.datasource.item.Id);
app.showPage(app.pages.ShopPageDemo);

在ShopPageDemo页面中,有一个AssetLocFiltered的表视图,该表视图使用以下代码在ondataload事件中设置查询参数:

widget.root.datasource.query.parameters.ParentLocationKey = 
widget.root.properties.ParentLocationKey;
widget.root.datasource.load();

这很好。问题是,当我点击浏览器刷新时,似乎清除了ShopPageDemo中的属性。如何处理浏览器刷新问题?我不太确定从哪里开始。

1 个答案:

答案 0 :(得分:0)

有多种方法可以做到这一点;但是,我通常采用的方法涉及深层链接。对于您的情况,您需要执行以下操作:

1。)在将您带到下一页的按钮上,添加以下代码:

var params = {
  key: widget.datasource.item.Id
};    
var page = app.pages.ShopPageDemo;
app.showPage(page);
google.script.history.replace(null, params, page.name);

2。)在 ShopPageDemo onAttach 事件处理程序上,添加以下内容:

google.script.url.getLocation(function(location) {
  widget.root.properties.ParentLocationKey = location.parameter.key;
  var ds = widget.datasource;
  ds.query.parameters.ParentLocationKey = widget.root.properties.ParentLocationKey;
  ds.load();
});

为了获得更好的性能,我会将 ShopPageDemo 数据源设置为不自动加载,并且还要在 onDetach 事件处理程序上卸载其数据,如下所示:widget.datasource.unload()

参考:
1. https://developers.google.com/apps-script/guides/html/reference/history
2. https://developers.google.com/apps-script/guides/html/reference/url