Reputation: 61
I tried to get values from an array from an object but it doesn't work. Can someone help me.
Here is the JSON parse:
let userContent = null;
try {
userContent = JSON.parse(entity.contactform_content);
} catch (e) {
userContent = String(userContent);
}
Return:
"contactform_id": "118",
"contactform_content":
"{\"display_name\":\"Peter\",\"user_email\":\"[email protected]\",\"user_nation\":\"be\",
\"category\":[{\"name\":\"Chinese Astrology\",\"value\":\"Chinese Astrology\"},{\"name\":\"Karmic Astrology\",\"value\":\"Karmic Astrology\"},{\"name\":\"Horoscopes\",\"value\":\"Horoscopes\"}],
\"available_time\":\"4 hours\",
\"time_slot\":\"2 hours\"}",
}
My attempt to get category value:
<TextField
autoComplete="off"
label="Category"
value={userContent.category}
/>
Upvotes: 0
Views: 35
Reputation: 4562
Try this:
<TextField
autoComplete="off"
label="Category"
value={userContent.category.map(x => x.name)}
/>
Upvotes: 2