离子幻灯片不更新动态数据

问题描述 投票:2回答:1

我使用的最新版本4.0.0离子的我试图更新按钮点击滑块的内容,但不更新内容的打字稿代码改变甚至数组值。在这里我们我的视图代码:

<ion-slides class="main-slide" pager=true loop="true" #mainSlider [options]="mainSliderOpts">
<ion-slide class="change-display" *ngFor="let product of products;">
    <div class="item-container">
        <div class="strike-title">Strike Price</div>
        <div class="devider"></div>

        <p class="description">
            To at least what price do you think the stock will move from its current price if
            <strong>${{product.price}}</strong>?
        </p>
        <div class="lose" [ngClass]="{ 'profit': product.profit > 0,'lose':   product.profit < 0 }">
            <span *ngIf="product.profit > 0">+</span>{{product.profit}}%
        </div>


        <div class="price-contract">
            PRICE PER CONTRACT: <strong>${{product.contractPrice}}</strong>
        </div>

        <ion-button class="next-btn" (click)=priceSliderChanged() expand="full" color="dark">Change Values</ion-button>

    </div>
</ion-slide>

这里是我的打字稿代码:

constructor() {
this.products = [{
        title: 'NFLX',
        price: 313.2,
        prices: [
            297.50,
            295.00,
            292.75,
            290.75
        ],
        profit: 4,
        contractPrice: 400 //defalt price       
    },
    {
        title: 'NFLX 1',
        price: 413.2,
        prices: [
            297.50,
            295.00,
            292.75,
            290.75
        ],
        profit: -6.6,
        contractPrice: 500 //defalt price       
    },
    {
        title: 'NFLX 2',
        price: 213.2,
        prices: [
            297.50,
            295.00,
            292.75,
            290.75
        ],
        profit: -7,
        contractPrice: 300 //defalt price       
    }
]

}

priceSliderChanged(){

this.mainSlider.getActiveIndex().then((index) => {
    var activeProduct = this.products[index];
    activeProduct.profit = this.randomIntFromInterval(-5, 6);
    activeProduct.contractPrice = this.randomIntFromInterval(350, 460);
    //setTimeout(()=>{
    this.mainSlider.update().then((d: any) => {
        // alert(d);
    });
});

}

正如你所看到contractPrice成功地改变,如果我安慰,但在“价格合同” DIV没有改变。

谢谢你的帮助。

angular ionic-framework ionic3 ionic4 swiper
1个回答
1
投票

我不知道这是否与你,但离子4测试版我有同样的问题的情况下,因为从1 getActiveIndex()回报指数而不是从0开始,例如,如果第一张幻灯片有效时,它会返回1,而不是0。

因此,尝试改变这种代码:

priceSliderChanged() {
  this.mainSlider.getActiveIndex().then((index) => {
  index-=1; //add this code
  var activeProduct = this.products[index];
  activeProduct.profit = this.randomIntFromInterval(-5, 6);
  activeProduct.contractPrice = this.randomIntFromInterval(350, 460);
 });
}

希望这可以帮助。

© www.soinside.com 2019 - 2024. All rights reserved.