【问题标题】:I cant able to make the listview for response from json我无法为来自 json 的响应制作列表视图
【发布时间】:2018-12-09 08:10:32
【问题描述】:

以下是我的 json 回复

这是我的 josn,它的结果对象有 student_name,我需要在我的 fetch 方法中显示我正在将响应转换为 response.json()

 {
"code": "200",
"status": "Success",
"Msg": "No Details",

"results": {
    "student_name": "Prasanna",
    "roll_no": "1",
    "id": "8",
    "std_id": "A180001",
    "org_id": "2",
    "institute_id": "2",
    "class_id": "1",
    "section_id": "1",
    }
 }

那我要克隆了

this.setState({
      dataSource: ds.cloneWithRows( responseJson.results),
 })

然后在我的渲染方法中

    dataSource={this.state.dataSource}

    renderSeparator= {this.ListViewItemSeparator}

    renderRow={(rowData) =>

   <View style={{flex:1, flexDirection: 'column'}} >

     <TouchableOpacity 
     onPress={this.GetItem.bind(this, rowData.student_name)}>

     <Text style={styles.textViewContainer}>
       {'id = ' + rowData.student_name}
    </Text>

 </TouchableOpacity>

   </View>

    }
  />

这就是我需要只显示名称的原因

我只需要显示学生姓名

【问题讨论】:

    标签: listview react-native fetch react-native-android react-native-ios


    【解决方案1】:

    renderRow 属性接受参数有点不合常规。改变

    renderRow={(rowData)=>{}}
    

    renderRow={({rowData})=>{}}
    

    里面额外的一组花括号用于解包参数

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-05-31
      • 1970-01-01
      • 2020-09-07
      • 1970-01-01
      • 2016-03-29
      • 2014-08-25
      • 2016-05-22
      • 1970-01-01
      相关资源
      最近更新 更多