从 ID 恢复数据

问题描述

我从我的 API 中获得了产品列表。 我创建了一个屏幕,其中列出了我所有的产品。当我单击这些产品之一时,我想在新屏幕中显示该产品的详细信息。所以我通过 this.props.data 将有问题的产品的 id 发送到子屏幕。 当我举一个这样的例子时:

Object {
    "cost": 1.86,"created_at": "2018-05-17T21:27:22Z","custom_fields": Array [],"description": "","family_id": 1,"id": 16,"incl_tax": 1,"is_visible": 1,"name": "AMORA Ketchup - 280 g","photo": Object {
      "_1_": Object {
        "id": 1,"order": 1,"title_fr": "tomato-ketchup-flacon-souple","url": "/i/p-6-1-6-146_5844_16_1.jpg",},"quantity": "0","reference": "","stock_status": "0","tax_rate_id": 1,"unit": "","updated_at": "2018-05-17T21:27:24Z","weight": 0,

我的 console.log 会如我所愿地返回“16”。

我完全迷失的地方,是如何从这个id中恢复我的子屏幕中所选产品的其他数据...... 例如,在这个屏幕中,我想显示家庭、价格、参考、照片、描述。 问题是我不知道如何获取特定的产品信息。我的API中有很多产品(获取产品的函数称为getProduct) 我制作了这个草稿屏幕,但我迷路了,不知道如何去做。

export default class information extends Component {
  constructor(props) {
    super(props);
    this.state = {
      productId: props.data,selectedId: '',setSelectedId: '',listData: '',name: '',stock : true,displayArray: [],reference: '',price: '',family: '',description: '',}   
    console.log('props',this.props.data)
  };

  initListData = async () => {
    let list = await getProduct(this.props.data);
   
    if (list) {
      this.setState({
        displayArray: list,reference: list.reference,name: list.name,price: list.price,family: list.family_id,description: list.description,stock: list.stock_status,loadMoreVisible: (list.length >= 15 ? true : false),currentPage: 2
      });
    }
  };

  async UNSAFE_componentwillMount() {
    this.initListData();
  }

  render() {
    console.log(this.state.name)
 // console.log('ça c\'est data = ',this.props.data );
 // console.log('ça c\'est les props =',this.props );
 // console.log('ça c\'est le state = ',this.state );
    return (
      <ScrollView contentContainerStyle={{flex: 1}}>          
          {
           // this.state.displayArray.map((item,i) => (
              <ListItem bottomDivider>                
                  <Icon name='flight-takeoff' />
                  <ListItem.Content>
                  <ListItem.Title style={{color: '#d35400'}}>{this.state.name}</ListItem.Title>
                  <ListItem.Subtitle style={{ color: '#F78400' }}>
                          {i18n.t("information.family")}: {this.state.family}
                  </ListItem.Subtitle>
                  <ListItem.Subtitle style={{ color: '#F78400' }}>
                          {i18n.t("information.reference")}: {this.state.reference}
                  </ListItem.Subtitle>
                  <ListItem.Subtitle style={{ color: '#F78400' }}>
                          {i18n.t("information.id")}: {this.state.productId}
                  </ListItem.Subtitle>
                  <ListItem.Subtitle style={{ color: '#F78400' }}>
                          {i18n.t("information.cost")}: {this.state.cost}
                  </ListItem.Subtitle>
                  <ListItem.Subtitle style={{ color: '#F78400' }}>
                          {i18n.t("information.description")}: {this.state.description}
                  </ListItem.Subtitle>
                  <ListItem.Subtitle style={{ color: '#F78400' }}>
                          {i18n.t("information.stock")}: {this.state.stock}
                  </ListItem.Subtitle>     
                  </ListItem.Content>
              </ListItem>
          //  ))
          }
      </ScrollView>
      );
    }    

}

我希望我的要求很明确,我的英语也不会太差。

你能指导我并帮助我吗?感谢您的解释。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...