显示对象值的循环

时间:2019-05-09 07:23:03

标签: loops react-native

我希望通过循环显示对象的值。我怎样才能做到这一点 在React Native中,我不想写这个

<Label>{this.props.navigation.state.params.item.city}</Label>
<Label>{this.props.navigation.state.params.item.name}</Label>
<Label>{this.props.navigation.state.params.item.family}</Label>
<Label>{this.props.navigation.state.params.item.typofcar}</Label>
...

我想为此使用循环 。 我该怎么办?

{ "key": "1", "city": "تهران", "name": "رامین" ,"family": "خوش روان","typofcar": "glx","colorcar": "قرمز","model": "85","flat1": "1",
    "flat2": "0","flat3": "1","flat4": "0", "phone": "023432","mobile": "0125353","adress1": "aggaRWAGARG-WEARG-AERG","adress2": "AWREGARG-WRGAR-",
    "qulity": "55","cards": "GGHHGHH",
    "giftus": "15222","p2": "5142","year": "1364","girbox": "jbbjkl45345","option": "tghhhfrde","price1": "100024"
    ,"pric2": "435453453","perprice": "5554243",
    "daytime": "cxxgfuvyi","ext": "hkudtyjsryjfgjdtyjdtyj","codcar": "564538","codf": "55238735","ostan": "teh","timeofroz": "66",}

1 个答案:

答案 0 :(得分:1)

您可以这样做

将您的对象存储到变量obj中并对其进行迭代。

Object.keys(obj).forEach(function(key,index) {
    return(
      <Label>{obj[key]}</Label>
    )
});