gpt4 book ai didi

javascript - 如何选择任何数量并更改其值?

转载 作者:行者123 更新时间:2023-11-30 19:41:24 25 4
gpt4 key购买 nike

我是 ionic 3 的新手,想了解代码请帮助我。我想选择任何项目,它的值得到的更改小计可能会反射(reflect)到它的输出。

cart.ts

private _values1 = [" 1 ", "2", " 3 "," 4 "," 5 "," 6 "];

firstDropDownChanged(_values1: any)
{
this.currentPrice = (parseInt(this.product.subtotal) * this._values1);
console.log(this.currentPrice);
this.product.subtotal =this.currentPrice;
console.log(this.product._values1);
}

cart.html

  <span style="font-size: 14px !important;">Qty:</span>   
<select class="sel" (change)="firstDropDownChanged()">
<option *ngFor='let v of _values1'>{{ v }}</option>
</select>

最佳答案

您可以使用 [(ngModel)] 作为 2 向数据绑定(bind)

<select class="sel" (change)="firstDropDownChanged()" [(ngModel)]="selectedValue">
<option *ngFor='let v of _values1' [ngValue]="v">{{ v }}</option>
</select>

因此,每次更改选项时,所选选项的当前值将在 selectedValue 变量中。在 .ts 文件中用作

firstDropDownChanged() {
this.currentPrice = this.product.subtotal * this.selectedValue;
console.log(this.currentPrice);
this.product.subtotal =this.currentPrice;
}

Stackblitz Demo using ngModel

关于javascript - 如何选择任何数量并更改其值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55350480/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com