You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Power Apps创建新记录时Gallery残留历史内容的解决问询

核心原因分析

你遇到的问题是因为Gallery显示的是临时输入的本地内容,而非直接绑定数据源的记录。Reset(Gallery)仅重置控件本身的选中状态,不会清空内部输入框;Refresh针对的是数据源,无法影响本地临时输入;Clear无效则是因为Gallery未绑定可清空的临时集合。

具体解决方案

1. 用临时集合绑定Gallery(推荐方案)

  • 创建临时集合:用来存储Gallery中的临时联系人数据,比如命名为colTempContacts。
  • 设置Gallery数据源:将Gallery的Items属性改为colTempContacts。
  • 添加新联系人行:当需要新增联系人输入行时,执行以下代码:
    Collect(colTempContacts, {
        Contact_Name: "",
        Contact_Type: "",
        Display_Order: 1,
        Email_Address: "",
        Information: "",
        Title: ""
    })
    

2. 进入新记录屏幕时彻底清空数据

在新记录屏幕的OnVisible属性中添加以下代码,确保进入时Gallery和表单都是干净的:

Clear(colTempContacts);
ResetForm(Form_All_Request);
// 重置所有关联表单(按需添加)
ResetForm(Form_All_Status);
ResetForm(Form_PR_Aspects);
// ... 其他表单同理

3. 保存完成后清空临时集合

在你现有保存代码的末尾,添加清空临时集合的操作,避免残留数据:

// 现有保存代码...

// 保存完成后清空临时集合
Clear(colTempContacts);

4. 替代方案:直接重置Gallery内的输入控件

如果不想用临时集合,可在创建新记录时循环重置Gallery内的所有输入控件:

ForAll(Gallery10_7.AllItems,
    Reset(TextInput6_Vendor_Name_3);
    Reset(TextInput6_Type_7);
    Reset(TextInput6_VendorID_3);
    Reset(TextInput6_Vendor_Email_3);
    Reset(TextInput6_Vendor_Info_3);
)

注意:此方法需确保控件在Gallery实例中能被正确引用,若Power Apps自动给控件加了后缀(如TextInput6_Vendor_Name_3_1),建议改用临时集合方案更可靠。

代码调整示例(结合你的现有代码)

修改后的完整保存逻辑:

Set(StatusVar,"SAVED");

//Save Procurement Request Information 
If(DataCardValue18.Selected.Value="Procurement Intake",
    If(DataCardValue3.Selected.Value="No",
        Set(gblLastPatched,
        Patch('Procurement Requests',Defaults('Procurement Requests'),
            Form_All_Request.Updates,
            Form_All_Status.Updates,
            Form_PR_Aspects.Updates,
            Form_PR_Award_Type.Updates,
            Form_PR_Background.Updates,
            Form_PR_Continued_Services.Updates,
            Form_PR_Current_Vendor.Updates,
            Form_PR_Details.Updates,
            Form_PR_Exempt_Explain.Updates,
            Form_PR_Goals.Updates, 
            Form_PR_Grant_Method.Updates,
            Form_PR_Modification.Updates,
            Form_PR_Renewal.Updates,
            Form_PR_Requirements.Updates,
            Form_PR_Termination.Updates 
        )
        )
    )
);

//Loop through and Save Procurement Auto Contacts 
ForAll(
    Gallery10_7.AllItems,
    Patch('Procurement Auto Contacts',Defaults('Procurement Auto Contacts'),
        { 
        Contact_Name: TextInput6_Vendor_Name_3.Text,
        Contact_Type: TextInput6_Type_7.Text,
        Display_Order: Value(TextInput6_VendorID_3.Text),
        Email_Address: TextInput6_Vendor_Email_3.Text,
        Information: TextInput6_Vendor_Info_3.Text,
        TempParentID: gblLastPatched.ID,
        Title: TextInput6_Vendor_Name_3.Text
        }
    )
);

// 清空临时集合,重置Gallery
Clear(colTempContacts);

内容的提问来源于stack exchange,提问作者Corrie Sigler

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.12 22:53:10