[英]Mapping an object array into a state
根據您的要求保存您的響應以進行定制。 按照代碼段。 將其保存為狀態,然后將此狀態傳遞給孩子。 通過使用componentWillReceiveProps
更新子狀態。
示例: 在React中使用代碼
let response = { slug: ['slug required'], name: ['name'], address_1: ['address_1'], address_2: ['address_2'], city: ['city'], state: ['state'], postal_code: ['postal_code'], country_code: ['country_code'], phone_number: ['phone_number '] } const keys = Object.keys(response) keys.map((m)=>{ response[m] = Array.isArray(response[m]) ? response[m][0] : response[m] }) console.log("customed response",response)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.