我有一个名为选项的对象数组。如何从离子选择选项中获取值
这是我的html代码
<ion-item>
<ion-label>place</ion-label>
<ion-select [(ngModel)]="place" (click)="optionsFn(item);">
<ion-option value="item" *ngFor="let item of options">{{item.name}} {{item.price}}</ion-option>
</ion-select>
</ion-item>
{{salespriceOp}}
{{quantityOp}}
这是我的.ts文件中的代码
product_option_value_idOp
priceOp
salespriceOp
quantityOp
skuOp
nameOp
options = [
{
"product_option_value_id": "45",
"name": "Bangalore Auto",
"quantity": "12",
"sku": "56876",
"price": "100.00",
"salesprice": "50"
},
{
"product_option_value_id": "51",
"name": "Hyderabad Auto",
"quantity": "23",
"sku": "56543",
"price": "200.00",
"salesprice": "60"
},
{
"product_option_value_id": "52",
"name": "Delhi Auto",
"quantity": "14",
"sku": "98767",
"price": "300.00",
"salesprice": "80"
}
];
constructor(public navCtrl: NavController) {
}
optionsFn(item) {//here item is an object
console.log(item);
this.product_option_value_idOp = item.product_option_value_id;
this.priceOp = item.price;
this.salespriceOp = item.salesprice;
this.quantityOp = item.quantity;
this.skuOp = item.sku;
this.nameOp = item.name;
}
越来越不确定我能够调用该函数,但我在
console.log(item)
它不工作,因为你从选择标签调用'optionsFn'函数。你必须将它添加到'ion-option'标签 – ranakrunal9
@ ranakrunal9我认为只有在'ion-option'标签中使用'ion-select'标签时,才应该使用点击功能,我不能调用这个功能本身 –
因此,为了使用它离子选择,你必须在'ion-option'中分配'[value] = item',并且需要在'optionsFn'函数中使用'gaming'。所以从'optionsFn'中移除参数并尝试检查。 – ranakrunal9