简体   繁体   English

无法使用语言环境数据解析数据库中的数据

[英]Unable to parse data from database with locale data

I am relatively new to React but I was previously working with the Contentful delivery API and decided to switch to the Content Management API because it better suited my needs.我对 React 比较陌生,但我之前使用过内容交付 API 并决定切换到内容管理 API,因为它更适合我的需求。 Now when I import all of the fields in my entries they all have what appears to be a locale in front of them.现在,当我导入条目中的所有字段时,它们前面似乎都有一个语言环境。 This is what it looks like: {en-US: "textile"} and here is a screenshot of it in the console of the browser:这是它的样子: {en-US: "textile"}这是浏览器控制台中的截图:

Screenshot of console output from browser来自浏览器的控制台 output 的屏幕截图

I'm sure it is a pretty simple fix but for the life of me I cannot figure out how to parse this data and I have been unable to find any help on the Internet.我确信这是一个非常简单的修复,但对于我的生活,我无法弄清楚如何解析这些数据,而且我无法在 Internet 上找到任何帮助。 Could someone please help me out, I just want the text that I was able to originally get so easily with the delivery API.有人可以帮帮我吗,我只想要我最初能够通过交付 API 轻松获得的文本。

Hoping there is going to be only one key 'en-us' inside each object希望每个 object 中只有一个“en-us”键

 var industry = {'en-us':'textile'}; var featured = {'en-us':true}; var dbData= {industry,featured}; var newData = {} //iterate and extract the values to newData Object.keys(dbData).forEach(key=>{ newData[key] = Object.values(dbData[key])[0] }) console.log(newData)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM