这是我的响应数组:
"options": [
{
"productoption_id": "3",
"option_id": "1",
"option_name": "Color",
"type": "select",
"optionvalue": [
{
"product_optionvalue_id": "5",
"optionvalue_id": "1",
"optionvalue_name": "Green",
"product_optionvalue_price": "0.00000000",
"product_optionvalue_prefix": "",
"product_optionvalue_weight": "0.00000000",
"product_optionvalue_sku": "",
"product_optionvalue_weight_prefix": "",
"product_optionvalue_default": 1,
"optionvalue_image": "",
"product_optionvalue_attribs": ""
},
{
"product_optionvalue_id": "6",
"optionvalue_id": "2",
"optionvalue_name": "Red",
"product_optionvalue_price": "0.00000000",
"product_optionvalue_prefix": "",
"product_optionvalue_weight": "0.00000000",
"product_optionvalue_sku": "",
"product_optionvalue_weight_prefix": "",
"product_optionvalue_default": "0",
"optionvalue_image": "",
"product_optionvalue_attribs": ""
}
],
,并且我需要在下拉菜单中显示“ option_name”作为标题和“ optionvalue_name”。 当我尝试在下拉列表中显示optionvalue_name时,显示错误。
错误错误:“未捕获(承诺):语法错误:JSON.parse:JSON数据的第1行第1列出现意外字符
html:
<ion-grid *ngFor="let tms of optionprd;">
<ion-row *ngIf="varibleprd == 'variable'">
<ion-label>{{tms.option_name}}:</ion-label>
<ion-select [(ngModel)]="color">
<ion-option value="s">Select</ion-option>
<ion-option *ngFor="let color of dropoptions;" value="r">{{color.optionvalue_name}}</ion-option>
</ion-select>
</ion-row>
</ion-grid>
Ts:
this.optionprd = JSON.parse(JSON.stringify(this.data.data.product.options));
console.log(JSON.stringify("variable: "+JSON.stringify(this.optionprd)));
this.dropoptions = JSON.parse(JSON.stringify( this.optionprd.optionvalue));
console.log(JSON.stringify("variable1: "+JSON.stringify(this.dropoptions)));