我有一個 API,它以以下格式返回數據:[ { "id": 12, "acf": { "address": { "city": "Bandar Penawar", "state": "Johor", "country": "Malaysia", } }, { "id": 16, "acf": { "address": { "city": "Some City", "state": "Arizona", "country": "United States", } }]現在,我正在獲取具有以下計算代碼的國家和州列表:computed: { countries() { const countries = new Set(); this.$store.state.posts.forEach((post) => countries.add(post.acf.address.country) ); return Array.from(countries); }, states() { const states = new Set(); this.$store.state.posts.forEach((post) => states.add(post.acf.address.state) ); return Array.from(states); }, },這將返回兩個單獨的數組,countries并且states,如何按國家/地區以及該國家/地區內的州組織數組?
將 API 數據中的州添加到國家/地區
吃雞游戲
2023-10-14 10:00:28