首页 文章

删除嵌套的Appmaker列表项(而不是项本身)的多对多关系

提问于
浏览
1

我在Cloud SQL中有3个表:person,tag,person_tag

在Appmaker中,我有一个表单小部件(datasource:person)和一个列表小部件(datasources.person.relations.tag_id),显示绑定到datasource.item.name的文本 . 这很有效,只显示分配给所选人员的标签 .

我在标签列表项上放了一个删除按钮,这样我就可以从该人的记录中删除标签 . 但是,我无法弄清楚如何设置onClick事件来删除关系(person_tag记录)而不是标记本身(来自标记表) . 想法?

2 回答

  • 1

    App Maker会将此代码生成为 delete current item

    widget.datasource.deleteItem();

    但正如问题中提到的那样,我们不需要删除该项,而是打破两个记录之间的关系 . 为此,您可以修改项目数组,App Maker将智能地同步您的更改:

    // Here widget is delete button and
    // widget.parent will be list's row (or grid's cell depending on the UI)
    // and by getting its position in the list/grid
    // we will get index of datasource's item (relation) we need to break
    var row = widget.parent;
    var index = row.childIndex;
    
    // remove one item at index, this will force
    // App Maker to break the relation
    app.datasources.Person.item.Tags.splice(index, 1);
    

    你可以在Vendor Ratings template找到这种模式

  • 0

    我是这样做的:给定Person和Tags之间的多对多关系,从两个表中选择当前选择的项目 . 找到关系数组中第一个项的索引,然后将其删除 .

    var person = widget.root.descendants.Table1.datasource.item;
    var tag = widget.root.descendants.Table2.datasource.item;
    
    personIndex = person.Tags.indexOf(person);
    if (personIndex !== -1) person.Tags.splice(personIndex, 1);
    

相关问题