import React, {Component} from 'react' ;
import {
AppRegistry,
StyleSheet,
Text,
View,
ListView,
TouchableOpacity,
} from 'react-native' ;
export default class fenZhuTableView extends Component {
constructor(props){
super (props);
var getSectionData = (dataBlob,sectionID)=>{
return dataBlob[sectionID];
};
var getRowData = (dataBlob,sectionID,rowID)=>{
return dataBlob[sectionID+':' +rowID];
}
this .state = {
dataSource: new ListView.DataSource({
getSectionData:getSectionData,
getRowData:getRowData,
rowHasChanged:(r1,r2) => r1 !== r2,
sectionHeaderHasChanged:(r1,r2) => r1 !== r2
})
}
}
render(){
return (
<ListView
dataSource={this .state.dataSource}
renderRow={this .renderRow}
renderSectionHeader={this .renderSectionHeader}
/>
);
}
renderSectionHeader(sectionData,sectionID){
return (
<View>
<Text style={{backgroundColor:'red' }}>{sectionData+sectionID}</Text>
</View>
)
}
renderRow(rowData){
return (
<View>
<Text>{rowData}</Text>
</View>
)
}
componentDidMount() {
var jsonData = Car.data;
var dataBlob = {};
sectionIDs = [],
rowIDs = [],
cars = [];
for (var i = 0 ; i< 10 ; i++){
sectionIDs.push(i);
dataBlob[i] = 'section' + i;
rowIDs[i] = [];
for (var j= 0 ; j<5 ; j++){
rowIDs[i].push(j);
dataBlob[i +':' +j] = 'section' + i + '--row' + j;
}
}
this .setState({
dataSource:this .state.dataSource.cloneWithRowsAndSections(dataBlob,sectionIDs,rowIDs)
})
}
}