首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Ion-slides不更新动态数据

Ion-slides不更新动态数据
EN

Stack Overflow用户
提问于 2019-02-12 00:23:57
回答 1查看 827关注 0票数 3

我使用的是最新版本的ionic 4.0.0,我试图在单击按钮时更新滑块的内容,但它不会更新内容,甚至在TypeScript代码中更改了数组值。下面是我的视图代码:

代码语言:javascript
复制
<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>

下面是我的打字代码:

代码语言:javascript
复制
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() {

代码语言:javascript
复制
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,但没有在“.Price-contract”目录中进行更改。

谢谢你的帮助。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-02-12 11:43:01

我不确定这是不是你的情况,但在离子4测试版中,我遇到了同样的问题,因为getActiveIndex()从1返回索引,而不是从0。例如,如果第一张幻灯片是活动的,它将返回1而不是0。

因此,尝试更改以下代码:

代码语言:javascript
复制
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);
 });
}

希望这能有所帮助。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/54634850

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档