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\":\"peter@gmail.com\",\"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}
/>
Try this:
<TextField autoComplete="off" label="Category" value={userContent.category.map(x => x.name)} />
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.