亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何在深層嵌套循環中共享img?JS 角 DEVEXTREME

如何在深層嵌套循環中共享img?JS 角 DEVEXTREME

慕婉清6462132 2023-10-20 15:30:54
我所有的代碼都在這里:https://stackblitz.com/edit/angular-devextrem-gallery?file=src/app/app.component.html我需要在深層嵌套循環中共享圖庫。問題可能是 dataSource 數組。上面的代碼您可以看到如何循環打印圖像,但我需要使用 dev Extreme gallery 在畫廊中共享相同的圖像。如果您在這里推薦我任何解決方案但僅使用畫廊,我持開放態度......
查看完整描述

1 回答

?
手掌心

TA貢獻1942條經驗 獲得超3個贊

這是解決方案。通過映射訓練 id 特定數組,而不是單個數據源數組。所以基本上將你的 html 更改為:-


<div class="modal-header">

    <div class="box-one">

        <div class="header"></div>

    </div>

</div>


<div class="modal-body">

    <div class="wrapper">

        <ng-container *ngIf="firstPage">

            <div class="column-holder" *ngFor="let training of aca.trainingExercises; let i = index;">

                <div class="single-exe">

                    <div class="holder-name">

                        <ng-container *ngIf="firstPage">

                            <div style="display: flex; width: 100%; justify-content: center; height: 100%;">

                                <!-- <div *ngFor="let singleImg of training.exercise.pictureList"

                                    style="width: 20%; height: 20vh; margin: 0 20px;">

                                    <img width="100%" height="100%" [src]="singleImg.url" alt="img exercise">

                                    <p class="description-below-img"> {{ truncate(singleImg.description) }}</p>

                                </div> -->

                                <dx-gallery #gallery id="gallery" [dataSource]="dataSourceImg.get(training.id)"

                                    [loop]="true" [height]="300" [showNavButtons]="true" [showIndicator]="true">

                                </dx-gallery>

                            </div>

                        </ng-container>

                    </div>

                </div>

            </div>

        </ng-container>

    </div>

</div>

然后將數據源從數組更改為映射,如下所示:-


dataSourceImg: Map<number, string[]> = new Map();

然后將 ngInit 代碼更改為:-


this.aca.trainingExercises.forEach(training => {

      this.dataSourceImg.set(training.id, []);

      training.exercise.pictureList.forEach(img => {

        this.dataSourceImg.get(training.id).push(img.url);

      });

    });

工作堆棧閃電戰

https://stackblitz.com/edit/angular-devextrem-gallery-92fa1f?file=src/app/app.component.ts


查看完整回答
反對 回復 2023-10-20
  • 1 回答
  • 0 關注
  • 149 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號