React 组件在来自 JSON 对象的选项卡中呈现动态内容

React component render dynamic content in tabs from a JSON object

在我的 React 组件中,我无法从 JSON 对象呈现动态选项卡。 我能够检索 JSON 数据键和值数组,但无法在 UI.

中呈现它

我正在使用 PrimeReact UI 组件。 https://www.primefaces.org/primereact/#/tabview

组件

export default class Report extends Component {


    render() {                          

        const { splitGroupedStartingMaterials } = this.state

        return (
            <div>
                <TabView>
                    {
                        Object.keys(splitGroupedStartingMaterials).forEach(k => {
                            console.log('k : ' + k, JSON.stringify(splitGroupedStartingMaterials[k]));
                            return (<TabPanel header={'Family'}>
                                simple content here for testing
                            </TabPanel>);
                        })
                    } 
                </TabView>                              
            </div>);
        }
}                                   

JSON 数据:-

"splitGroupedStartingMaterials": {
  "1": [
    {
      "id": 45598,
      "symbol": "Mn",
      "description": "Mn(NO3)2 (fr mn flake)_[10377-66-9]",
      "priority": 1,
      "matrices": "HNO3",
      "family": "F2.0",
      "splitGroup": "1"
    },
    {
      "id": 45636,
      "symbol": "Ti",
      "description": "(NH4)2TiF6 (as Ti)_[16962-40-6]",
      "priority": 2,
      "matrices": "F- : HNO3",
      "family": "F1.1",
      "splitGroup": "1"
    }
  ],
  "2": [
    {
      "id": 45572,
      "symbol": "Cr",
      "description": "CrCl3 (fr Cr shot)_[10025-73-7]",
      "priority": 2,
      "matrices": "HCl",
      "family": "F3.1",
      "splitGroup": "1_2"
    }
  ]
}                                       

更新:-

控制台日志:-

10:46:28.769 InOrganicCreateCustomQuote.jsx:704 k : 1 [{"id":45621,"symbol":"Sc","description":"Sc2O3 (as Sc)_[256652-08-1]","priority":1,"matrices":"HNO3","family":"F2.0","splitGroup":"1"},{"id":45636,"symbol":"Ti","description":"(NH4)2TiF6 (as Ti)_[16962-40-6]","priority":2,"matrices":"F- : HNO3","family":"F1.1","splitGroup":"1"},{"id":45640,"symbol":"V","description":"V2O5 (as V)_[1314-62-1]","priority":1,"matrices":"HNO3","family":"F2.0","splitGroup":"1"}]

10:46:28.770 InOrganicCreateCustomQuote.jsx:704 k : 2 [{"id":45646,"symbol":"Zr","description":"ZrCl2O (as Zr)_[7699-43-6]","priority":1,"matrices":"HCl","family":"F3.1","splitGroup":"1_2"}]

对于此代码,未呈现任何选项卡

你能试试吗:

export default class Report extends Component {


    render() {                          

        const { splitGroupedStartingMaterials } = this.state

        return (
            <div>
                <TabView>
                    {
                        Object.keys(splitGroupedStartingMaterials).map(k => (
                            <TabPanel header={'Family'}>
                                simple content here for testing
                            </TabPanel>
                        ))
                    } 
                </TabView>                              
            </div>);
        }
}