【问题标题】:How to cause index.view to be updated when the Save command is executed in an open dialog如何在打开的对话框中执行保存命令时更新 index.view
【发布时间】:2022-11-19 17:36:37
【问题描述】:

在打开的对话框中执行保存命令时,父 index.view 不会更新。对于 SaveAndClose 命令,一切都很好。在产品对象上的 https://github.com/alex-kukhtin/A2v10.Web.Sample.git 进行了测试。平台A2v10,不幸的是我还不能标记。

<Dialog xmlns="clr-namespace:A2v10.Xaml;assembly=A2v10.Xaml" 
        Title="{Bind Product.Id, Format='@[Product] [{0}]'}">
    <Dialog.Buttons>
        <Button Content="@[SaveAndClose]" Command="{BindCmd SaveAndClose, ValidRequired=True}"/>
        <Button Content="@[Save]" Command="{BindCmd Save, ValidRequired=True}"/>
        <Button Content="@[Cancel]" Command="{BindCmd Close}"/>
    </Dialog.Buttons>
    <TabPanel>
        <Tab Header="@[General]">
            <Grid>
                <TextBox Label="@[Name]" Value="{Bind Product.Name}"/>
                <TextBox Label="@[BarCode]" Value="{Bind Product.BarCode}" Width="20rem"/>
                <TextBox Label="@[Article]" Value="{Bind Product.Article}" Width="20rem"/>
                <TextBox Label="@[Memo]" Value="{Bind Product.Memo}" Multiline="True" Rows="3"/>
            </Grid>
        </Tab>
        <Tab Header="@[Images]" Padding="1rem">
            <Image Source="{Bind Product.Picture}" Limit="100"
                Base="/catalog/product" Height="18rem"/>
        </Tab>
    </TabPanel>
</Dialog>

PS:由Edit命令调用


I try: executing the Save command in an open dialog
I expecting: The parent index.view is update

【问题讨论】:

    标签: typescript xaml


    【解决方案1】:

    此行为是设计使然。

    更新取决于调用对话框的方式。

    如果编辑命令被调用,索引在对话框返回后更新编辑元素保存并关闭命令。

    节省命令不会关闭对话框,因此调用代码不会控制。

    解决问题最简单的方法是使用事件。

    指定当元素被保存时,您想要引发一个事件并在索引中捕获它。

    例如像这样:

        <Dialog SaveEvent="app.element.saved">
    

    里面索引模板.ts

    const template: Template = {
        events: {
            'app.element.saved': elementSaved
        }
    };
    
    export default template;
    
    function elementSaved(elem) {
       const ctrl: IController = this.$ctrl;
       // Find the element in the list and update if found or add if not.
       let found = this.Items.find(x => x.Id === elem.Id);
       if (found)
          found.$merge(elem);
       else
          this.Items.$append(elem); 
    }
    

    最后但并非最不重要。如果您正在使用事件,请使用节目命令,而不是编辑命令。这将避免不必要的更新。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-08-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多