【问题标题】:Accordion data is not updating in angular application手风琴数据未在角度应用程序中更新
【发布时间】:2019-12-24 10:43:50
【问题描述】:

我在我的 Angular 应用程序中使用 Syncfusion 组件。我无法将更新的数据绑定到手风琴组件。 请在下面的 stackblitz 链接中找到示例

Sample

在上面的代码中,如果我单击更改按钮,数据应该会更新,但手风琴中会显示空数据。 请让我知道如何解决此问题。

【问题讨论】:

    标签: angular syncfusion


    【解决方案1】:

    您应该使用 track by 来了解数据更改的角度。

    *ngFor = "let item of data1;trackBy:identify"
    
    identify(index,item){
      return this.count;
     }
    

    whatch this

    【讨论】:

      【解决方案2】:

      实际上我不喜欢文档中提到的方法,我认为它是为了将项目添加到现有手风琴中,而不是为了将其完全重新渲染为您的示例。

      因为你有 *ngIf 指令有条件地显示它。我们可以欺骗 Angular 来重新渲染它,如下所示:

       this.data1.length = 0;
          setTimeout(() => {
            this.data1 = this.count % 2 == 0 ? [...this.items] : [...this.items1];   
          });
      

      请参阅 Stackblitz sample。

      【讨论】:

        【解决方案3】:

        从documentation 看来,您需要使用AccordionComponent 中可用的公共方法addItem(),感谢您的@ViewChild,您可以检索该方法。

        希望这会有所帮助!

        【讨论】:

        • addItem() 将添加新项目,但我们无法重新加载完整的数据源。
        猜你喜欢
        • 2014-09-25
        • 2023-01-03
        • 2015-07-21
        • 1970-01-01
        • 1970-01-01
        • 2016-01-07
        • 2015-09-19
        • 2017-10-10
        • 2017-10-26
        相关资源
        最近更新 更多