如何在App Maker数据源中设置当前项目? [英] How to set current item in App Maker datasource?

查看:71
本文介绍了如何在App Maker数据源中设置当前项目?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这似乎很基本,但我似乎无法弄清楚如何从数据源手动设置当前项目以供使用?

为了说明:我有一个表,我注意到当我选择一行来编辑字段时,该行的项目成为当前项目,因此,如果我在该行上有一个链接以导航至页面,所选项目的行将是导航页面的datasource.item.

但是,我还注意到,如果我只是将鼠标悬停在一行上,而没有选择编辑字段,那么如果我单击导航到页面的链接,它将加载先前选择/编辑的任何行的数据.因此,我想知道如何做到这一点,以便仅在mouse:over上(或单击快捷方式,而无需事先单击该行中的另一个字段),datasource.item将更新为鼠标移过的行首先需要编辑行中的字段.我希望这是有道理的.

我们非常感谢您的协助.谢谢!

解决方案

为什么会发生:

AM code: generate button click event
User code: handle button's click event
User code: navigate user to different page
AM code: destroy DOM of current page
AM code: build DOM for new page
-- dead code after this line
AM code: row click event handler
AM code: change datasource's current item

行的click事件处理程序永远不会获得控制权,因为行已被用户代码破坏.

Morfinismo 的解决方案有什么作用?

AM code: generate button click event
User code: handle button's click event
AM code: row click event handler
AM code: change datasource's current item
-- moved lines
User code: navigate user to different page
AM code: destroy DOM of current page
AM code: build DOM for new page

这里有更多技术细节:事件循环

在App Maker中,此问题可以通过

解决

  1. setTimeout
  2. 强制使用用户代码更新当前商品

 // button's onClick event handler
app.datasource.ListDatasource.selectKey(widget.datasource.item._key);
 

  1. CustomProperties

 // button's onClick event handler
app.pages.ShowMeNext.properties.Key = widget.datasource.item._key;
app.showPage(app.pages.ShowMeNext);

// next page's onAttach event handler
app.datasources.RecordDatasource.filters._key._equals = app.currentPage.properties.Key;
app.datasources.RecordDatasource.load();
 

  1. URL参数 // button's onClick event handler var params = { key: widget.datasource.item._key }; var page = app.pages.ShowMeNext; app.showPage(page); google.script.history.replace(null, params, page.name); // next page's onAttach event handler google.script.url.getLocation(function(location) { app.datasources.RecordDatasource.filters._key._equals = location.parameters.key; });

    1. 使用全局范围在页面之间传递值

     // button's onClick event handler
    window.key = widget.datasource.item._key;
    
    // next page's onAttach event handler
    app.datasources.RecordDatasource.filters._key._equals = window.key;
     

    ListDatasource -列表/网格/表数据源

    RecordDatasource -专用于特定记录的数据源(单记录数据源)

    This seems basic but I can't seem to figure out how to manually set the current item to work with from the datasource?

    To illustrate: I have a table and I notice that when I select a row to edit a field, the item of that row becomes the current item, so if I have a link on that row to Navigate to a page, the row of the item selected will be the datasource.item for the navigated page.

    However, I also notice that if I just hover over a row, without selecting to edit a field, if then I click on a link to Navigate to a page, it loads the data of whatever row was previously selected/edited. Therefore I'm wondering how to make it so that just on a mouse:over (or click on the shortcut without a prior click on another field in the row) the datasource.item will update to the the row the mouse has gone over instead of requiring to edit a field on the row first. I hope that makes sense.

    Assistance is much appreciated. Thank you!

    解决方案

    Why it happens:

    AM code: generate button click event
    User code: handle button's click event
    User code: navigate user to different page
    AM code: destroy DOM of current page
    AM code: build DOM for new page
    -- dead code after this line
    AM code: row click event handler
    AM code: change datasource's current item
    

    Row's click event handler never gets control, because row is destroyed by user's code.

    What Morfinismo's solution does?

    AM code: generate button click event
    User code: handle button's click event
    AM code: row click event handler
    AM code: change datasource's current item
    -- moved lines
    User code: navigate user to different page
    AM code: destroy DOM of current page
    AM code: build DOM for new page
    

    Here are more tech details: Event Loop

    In App Maker this problem can be solved with

    1. setTimeout
    2. Force current item update in user code

    // button's onClick event handler
    app.datasource.ListDatasource.selectKey(widget.datasource.item._key);
    

    1. CustomProperties

    // button's onClick event handler
    app.pages.ShowMeNext.properties.Key = widget.datasource.item._key;
    app.showPage(app.pages.ShowMeNext);
    
    // next page's onAttach event handler
    app.datasources.RecordDatasource.filters._key._equals = app.currentPage.properties.Key;
    app.datasources.RecordDatasource.load();
    

    1. URL parameters and history - this approach is used in most template apps, because it also implements deep linking on some extent.

    // button's onClick event handler
    var params = {
                   key: widget.datasource.item._key
                 };
    var page = app.pages.ShowMeNext;
    app.showPage(page);
    google.script.history.replace(null, params, page.name);
    
    // next page's onAttach event handler
    google.script.url.getLocation(function(location) {
      app.datasources.RecordDatasource.filters._key._equals = location.parameters.key;
    });
    

    1. Passing value between pages using global scope

    // button's onClick event handler
    window.key = widget.datasource.item._key;
    
    // next page's onAttach event handler
    app.datasources.RecordDatasource.filters._key._equals = window.key;
    

    ListDatasource - list/grid/table datasource

    RecordDatasource - datasource dedicated for a specific record (single-record datasource)

    这篇关于如何在App Maker数据源中设置当前项目?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆