【问题标题】:How add / edit / remove many to many relationships in google app maker using tables?如何使用表格在谷歌应用程序制造商中添加/编辑/删除多对多关系?
【发布时间】:2019-08-05 13:41:41
【问题描述】:

我有以下两个模型之间的关系为中心的场景:资产和活动。

许多资产可以同时输入许多活动。

考虑到这一点 - 我想创建 UI,它允许我:

  • 从Activity的角度来看:

  • 通过从显示所有已创建资产的现有资产表中选择资产,将与活动相关的资产添加到表中。

  • 能够通过单击按钮删除关系(这不会删除表中的整条记录)。

请帮忙。提前谢谢!

我尝试将自定义代码绑定到一个按钮的 onClick 事件,该按钮与我想与关联活动取消关联的资产记录位于同一行:

var index = widget.root.datasource.item.Assets.indexOf(widget.datasource.item); widget.root.datasource.item.Assets.splice(index, 1);

这会返回:

无法读取未定义的属性“indexOf” 在 Strategy_TableView.Panel1.Table2.Table2Body.Table2Row.Button5.onClick:1:51

我还没有尝试找到将现有资产添加到相关活动表的方法。

【问题讨论】:

    标签: many-to-many google-app-maker


    【解决方案1】:

    建议的代码编辑以使其正常工作是:

    var datasourcerelation = widget.root.datasource.relations.Services;
    var index = datasourcerelation.items.indexOf(widget.datasource.item);
    datasourcerelation.items.splice(index, 1);
    

    无论出于何种原因,引用与 JS 数组函数相关的 datasource.item.Services 都不会为您提供所需的结果。我不确定这是为什么,但您必须改用 datasource.relations.Services

    关于添加到关系使用:

    var datasourcerelation = widget.root.datasource.item.Services;
    datasourcerelation.push(widget.datasource.item);
    

    请注意,在添加关系 datasource.item.Services 的情况下可以正常工作。我不确定为什么会有所不同。

    【讨论】:

    • 非常感谢您的回复,马库斯!我有一个问题,当我绑定到一个按钮时:var datasourcerelation = widget.root.datasource.relations.Services; var index = datasourcerelation.items.indexOf(widget.datasource.item); datasourcerelation.items.splice(index, 1); 我收到:Cannot read property 'indexOf' of null at Strategy_TableView.Panel1.Table2.Table2Body.Table2Row.Button5.onClick:2:38 我确定我是没有正确地做某事。我将在下一条评论中添加更多详细信息。
    • 详细信息:我有 2 张桌子。表 1 包含活动,并将活动作为数据源。表 2 包含资产并具有数据源活动:资产(关系)在具有资产记录的行的表中我添加了一个带有绑定 onClick 函数的按钮:var index = widget.root.datasource.item.Asset.indexOf(widget.datasource.item); widget.root.datasource.item.Asset.splice(index, 1); 我也尝试了您的变体,但点击它在这两种情况下都会返回:Cannot read property 'indexOf' of null at Strategy_TableView.Panel1.Table2.Table2Body.Table2Row.Button5.onClick:2:38
    • 关于使用:var datasourcerelation = widget.root.datasource.item.a3_Assets; datasourcerelation.push(widget.datasource.item); 我收到:Cannot read property 'push' of undefined at Strategy_TableView.Panel4.Table4Panel.Table4.Table4Body.Table4Row.Button6.onClick:2:20
    • 我唯一能想到的另一件事是您的 widget.root 没有分配给它的数据源,或者它没有作为数据源的活动。使用 widget.root 将指向您的顶级页面元素,因此请确保它确实将活动作为数据源。或者,只需将 widget.root.datasource 替换为 app.datasources.Activities。可能还有其他问题,但我会从这个开始。
    • @Veso Yanchev 我也刚刚注意到您的拼接函数可能分配给了错误的表。为了将资产添加到您的活动中,只有当您使用推送添加关系或者您可以使用选项设置为“@datasources.Assets.items”的多选时,您才需要指向资产的第三个表。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多