ios - React native ListView 数据源设置(dataSource)
天蓬老师
天蓬老师 2017-04-18 09:38:17
0
1
284

我想从json解析数据后以listview的形式表现出来:

现在的问题是: 因为json取到的是一个结构体数组,里面有姓名,有编号,但是我并不能将取到的这个结构体数组设置成数据源,提示错误如下:

请问应该如何解决?

代码如下:(其中try1为设置listview的样式,只是之前做的试验,因为数据源没有设置成功所以还没有设置关联的数据)

import React, { Component } from 'react';
import { AppRegistry, ListView,StyleSheet,TouchableOpacity,Image,TouchableHighlight,center,Text, View } from 'react-native';

class ListViewBasics extends Component {
  // 初始化模拟数据
  constructor(props) {
    super(props);
    const ds = new ListView.DataSource({rowHasChanged: (r1, r2) => r1 !== r2});
    this.state = {
      dataSource: ds.cloneWithRows(this.try2())
    };
  }
  try1(){
    return (<View style = {styles.cellRight}>
                <Text style={styles.celltext}>{'ss'}</Text>
             </View>
             );
  }
  try2(){
    fetch('http://v.6.cn/coop/iphone/index.php?padapi=coop-iphone-top.php')
    .then((response) => response.json())
    .then((jsondata) => {
//      console.log('!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!')
//      console.log("用户名:"+jsondata.getwealth.d[0].username)
//      console.log("房号为:"+jsondata.getwealth.d[0].rid)

      return jsondata.getwealth.d;
    })
  }

  render() {
    return (
      <View style={{paddingTop: 22}}>
        <ListView
          dataSource={this.state.dataSource}
          renderRow={(rowData1) => this.try1()}
        />
      </View>
    );
  }
}
天蓬老师
天蓬老师

欢迎选择我的课程,让我们一起见证您的进步~~

熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板
關於我們 免責聲明 Sitemap
PHP中文網:公益線上PHP培訓,幫助PHP學習者快速成長!