Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/15.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
如何修复json数据在react native中的呈现_Json - Fatal编程技术网

如何修复json数据在react native中的呈现

如何修复json数据在react native中的呈现,json,Json,我真的是个初学者 在renderItem()中 如果{item.value}小于等于10,我希望将输出呈现为“Text” 我该怎么做 谢谢你阅读这个问题。我会努力学习 我祈祷你能安全健康地远离冠状病毒 renderItem = ({item}) => { return( <View style={{flex:1,justifyContent:'center',alignItems:'center'}}> <View style={

我真的是个初学者

在renderItem()中 如果{item.value}小于等于10,我希望将输出呈现为“Text”

我该怎么做

谢谢你阅读这个问题。我会努力学习

我祈祷你能安全健康地远离冠状病毒

  renderItem = ({item}) => {
       return(
      <View style={{flex:1,justifyContent:'center',alignItems:'center'}}>
      <View style={{marginBottom:10}}>
      <Text>
        {item.from} 
        {item.to} 
        {item.value}
      </Text>
      </View>
    </View>
    )
  }


  componentDidMount(){
    const url = 'http://api-ropsten.etherscan.io/api?module=account&action=txlist&address=0x3A19E068Ea11b4D10D4516823eA9482fE70F1c52&startblock=0&endblock=99999999&sort=asc&apikey=IQN5KP8AKJ9WFTYNGZRJE7W3QHXPT4S65H'
    fetch(url)
    .then((response)=>response.json())
    .then((responseJson) => {
      this.setState({
        dataSource:responseJson.result
      })
    })
    .catch((error)=>{
      console.log(error)
    })
  }


  render(){
    return(
      <View style={{flex:1,justifyContent:'center', alignItems:'center'}}>

        <FlatList
          data={this.state.dataSource}
          renderItem={this.renderItem}
        />

      </View>
    )
  }


}
renderItem=({item})=>{
返回(
{item.from}
{item.to}
{item.value}
)
}
componentDidMount(){
常量url=http://api-ropsten.etherscan.io/api?module=account&action=txlist&address=0x3A19E068Ea11b4D10D4516823eA9482fE70F1c52&startblock=0&endblock=99999999&sort=asc&apikey=IQN5KP8AKJ9WFTYNGZRJE7W3QHXPT4S65H'
获取(url)
.then((response)=>response.json())
.然后((responseJson)=>{
这是我的国家({
数据源:responseJson.result
})
})
.catch((错误)=>{
console.log(错误)
})
}
render(){
返回(
)
}
}

您需要特别学习javascript和es6,这将在将来对您有很大帮助。现在,如果值小于或不小于10,您可以检入renderItem方法,然后返回所需的输出

renderItem = ({item}) => {
   if(item.value < 10){

   return(
  <View style={{flex:1,justifyContent:'center',alignItems:'center'}}>
  <View style={{marginBottom:10}}>
  <Text>
   {The text you want}
  </Text>
  </View>
  </View>)

   } else {
          return <View style={{flex:1,justifyContent:'center',alignItems:'center'}}>
  <View style={{marginBottom:10}}>
  <Text>
   {some value}
  </Text>
  </View>
  </View>

     }
renderItem=({item})=>{
如果(项目值<10){
返回(
{您想要的文本}
)
}否则{
返回
{some value}
}
谢谢。:)但这不是您想要的方式。即使item.value为10或更高,也必须进行渲染。如果小于10,我希望以不同的文本打印。