【问题标题】:Taking specific value from an object Array in react从反应中的对象数组中获取特定值
【发布时间】:2022-11-29 02:09:21
【问题描述】:

大家好,我想在用 get/all 调用数组后从数组中获取特定值。 我的代码如下:

fetchUserDetails=()=>{
        const username1 = localStorage.getItem('username')
        var axios = require('axios');
        var data = '';
        
        var config = {
          method: 'get',
          url: 'localhost:3000/users/getDataByUsername/'+username1,
          headers: { },
          data : data
        };
        
        axios(config)
        .then(function (response) {
          console.log(JSON.stringify(response.data));
          
        })  
        .catch(function (error) {
          console.log(error);
        });
    }

在这里,我获取了整个用户对象,在上面我只想显示整个项目中的 userEmail:

 <Form.Control type="text" value={this.state.userEmail}/>

知道我该如何实现吗?使用上述值不起作用

<Form.Control type="text" value={this.state.userEmail}/> 。我写了这段代码,但没有成功

【问题讨论】:

    标签: reactjs list get state


    【解决方案1】:

    你在哪里设置状态?在我看来,您只是在控制台记录数据。

       console.log(JSON.stringify(response.data));
    

    【讨论】:

    • 我是新手,无法对你的意思做出反应?我该怎么做?
    猜你喜欢
    • 2018-11-05
    • 2019-10-08
    • 1970-01-01
    • 2015-06-07
    • 1970-01-01
    • 1970-01-01
    • 2014-10-17
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多