【问题标题】:Parser data with format json in react反应中格式为 json 的解析器数据
【发布时间】:2018-02-13 19:26:38
【问题描述】:

我是 react.js 的新手,我正在尝试在表格中以 JSON 格式显示数据。所以我做的是:

import React from 'react';
import axios from 'axios';
class TableUser extends React.Component {
  constructor(props) {
    super(props); 
    this.state = {
      libelle_produit: ''
    };
  }
  componentDidMount(){
    axios
      .get('admin/prdtId/')
      .then(({ data })=> {
        this.setState({ 
          libelle_produit: data.libelle_produit
        });
      })
      .catch((err)=> {})
  }     
  render() {
      return <div>
      <p>{ this.state.libelle_produit }</p>
    </div>;
  }
}

export default TableUser;

我希望能够访问每个组件的 libelle 产品并将其打印在网站上

[{"libelle_produit":"测试产品"}]

谢谢

【问题讨论】:

  • 你能分享一下data.libelle_produit目前返回的内容吗?
  • 恢复是什么意思?
  • recover= recuperate recuerate libelle_produit from this format json [{"libelle_produit":"test produit"}]

标签: json reactjs parsing axios


【解决方案1】:
<div>
    { this.state.libelle_produit != '' ? this.state.libelle_produit.map( (item, index) => 
        <p>{libelle_produit</p>
    }
</div>

如果数组不为空,则循环遍历数组并返回带有 libelle_produit 标题的 p 标签

【讨论】:

  • 您需要为您的

    提供密钥
  • @Nath true,只做 key={index}
猜你喜欢
  • 2022-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-12-07
  • 1970-01-01
  • 2011-05-03
  • 1970-01-01
相关资源
最近更新 更多