Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
数据绑定在对象属性上不起作用 //我试图从嵌套对象呈现数据,但检索到错误消息 useffect(()=>{ axios .get('https://bodyshop.r2.software/wp-json/wp/v2/pages/2') 。然后(响应=>{ const posts=response.data; 常量tempObj={}; for(让输入posts[“post meta fields”]){ const modifiedKey=key.replace(“”,“”); tempObj[modifiedKey]=posts[“post meta fields”][key] } posts[“post meta fields”]=tempObj; 设置列表(员额) 控制台日志(posts); }) }, []) //嵌套对象 //职位={ // ... //“后元字段”:{ //优势之家:[''], //家庭:['35'], //_bg_info_1_home:['41'], //_bg_info_2_home:[''], //提供家庭:['38'], //销售主页:['36'], //视频主页:[''] // } // ... // }; //下面的例子 {posts[“post meta fields”][“\u bg\u sales\u home”][0]} //meyby解析json方法不正确的问题_Json_Reactjs_String_Object - Fatal编程技术网

数据绑定在对象属性上不起作用 //我试图从嵌套对象呈现数据,但检索到错误消息 useffect(()=>{ axios .get('https://bodyshop.r2.software/wp-json/wp/v2/pages/2') 。然后(响应=>{ const posts=response.data; 常量tempObj={}; for(让输入posts[“post meta fields”]){ const modifiedKey=key.replace(“”,“”); tempObj[modifiedKey]=posts[“post meta fields”][key] } posts[“post meta fields”]=tempObj; 设置列表(员额) 控制台日志(posts); }) }, []) //嵌套对象 //职位={ // ... //“后元字段”:{ //优势之家:[''], //家庭:['35'], //_bg_info_1_home:['41'], //_bg_info_2_home:[''], //提供家庭:['38'], //销售主页:['36'], //视频主页:[''] // } // ... // }; //下面的例子 {posts[“post meta fields”][“\u bg\u sales\u home”][0]} //meyby解析json方法不正确的问题

数据绑定在对象属性上不起作用 //我试图从嵌套对象呈现数据,但检索到错误消息 useffect(()=>{ axios .get('https://bodyshop.r2.software/wp-json/wp/v2/pages/2') 。然后(响应=>{ const posts=response.data; 常量tempObj={}; for(让输入posts[“post meta fields”]){ const modifiedKey=key.replace(“”,“”); tempObj[modifiedKey]=posts[“post meta fields”][key] } posts[“post meta fields”]=tempObj; 设置列表(员额) 控制台日志(posts); }) }, []) //嵌套对象 //职位={ // ... //“后元字段”:{ //优势之家:[''], //家庭:['35'], //_bg_info_1_home:['41'], //_bg_info_2_home:[''], //提供家庭:['38'], //销售主页:['36'], //视频主页:[''] // } // ... // }; //下面的例子 {posts[“post meta fields”][“\u bg\u sales\u home”][0]} //meyby解析json方法不正确的问题,json,reactjs,string,object,Json,Reactjs,String,Object,转换数据时,请执行以下操作: const modifiedKey=key.replace(“”,“”); 这使得下划线\u从键的前面消失,因此\u bg\u sales\u home将在转换的对象中未定义,并且在未定义的对象上访问[0]将抛出错误。 您必须使用bg\u sales\u home: //I tried to render data from the nested object, but retrieve the error message useEffect(()

转换数据时,请执行以下操作:

const modifiedKey=key.replace(“”,“”);
这使得下划线
\u
从键的前面消失,因此
\u bg\u sales\u home
将在转换的对象中未定义,并且在未定义的对象上访问
[0]
将抛出错误。 您必须使用
bg\u sales\u home

//I tried to render data from the nested object, but retrieve the error message
        useEffect(() => {
          axios
          .get('https://bodyshop.r2.software/wp-json/wp/v2/pages/2')
          .then(response => {
          const posts = response.data;
          const tempObj = {};
          for(let key in posts["post-meta-fields"]) {
              const modifiedKey = key.replace('_','');
              tempObj[modifiedKey] = posts["post-meta-fields"][key]
          }
          posts["post-meta-fields"] = tempObj;
                
        
          setList(posts)
          console.log(posts);
          })
        }, [])





        // nested object
        // posts = {
        // ...
        // 'post-meta-fields': {
        //   _bg_advantages_home: [''],
        //   _bg_banner_home: ['35'],
        //   _bg_info_1_home: ['41'],
        //   _bg_info_2_home: [''],
        //   _bg_offers_home: ['38'],
        //   _bg_sales_home: ['36'],
        //   _bg_video_home: ['']
        // }
        // ...
        // };

        //Example below 
        <div class="banner_title DrukFont">{posts["post-meta-fields"]["_bg_sales_home"][0]}</div>
        //meyby problem with parse incorrect parse  json method
{posts[“post meta fields”][“bg_sales_home”][0]}

您遇到了什么错误?Main.js:46 Uncaught TypeError:无法读取未定义的属性'title\u banner\u home'。对不起,我忘记了我尝试的类型没有下划线。它也不起作用
<div class="banner_title DrukFont">{posts["post-meta-fields"]["bg_sales_home"][0]}</div>