优化listview

This commit is contained in:
wushenghua
2016-02-23 16:54:27 +08:00
parent 3070f11460
commit 2235f5d95f
4 changed files with 8 additions and 16 deletions
+1 -3
View File
@@ -119,8 +119,6 @@ getInitialState: function() {
); );
}, },
pushInfo:function(index){ pushInfo:function(index){
console.log(this.state.dataSource.getRowData(0,index))
this.props.navigator.push({ this.props.navigator.push({
title: 'New Page', title: 'New Page',
component: <InfoPage movie={this.state.dataSource.getRowData(0,index)}> </InfoPage> component: <InfoPage movie={this.state.dataSource.getRowData(0,index)}> </InfoPage>
@@ -129,7 +127,7 @@ getInitialState: function() {
renderLoadingView:function(){ renderLoadingView:function(){
if (!this.state.isLoadingFail) { if (!this.state.isLoadingFail) {
return ( return (
<TouchableOpacity onPress={() =>this.fetchData()} style={styles.container} > <TouchableOpacity onPress={() =>this.fetchData} style={styles.container} >
<View style={styles.container}> <View style={styles.container}>
<Text> <Text>
{'点击刷新'} {'点击刷新'}
+4 -6
View File
@@ -60,8 +60,6 @@ export default class MyListView extends Component{
myfetchData(){ myfetchData(){
this.setState({isLoading:true,isLoadingFail:false}); this.setState({isLoading:true,isLoadingFail:false});
this.props.fetchData().then((responseData)=>{ this.props.fetchData().then((responseData)=>{
console.log('接受到数据');
console.log(responseData);
this.setState({ this.setState({
isLoading: false, isLoading: false,
isLoadingFail: false, isLoadingFail: false,
@@ -104,13 +102,13 @@ export default class MyListView extends Component{
pushInfo(index){ pushInfo(index){
this.props.navigator.push({ this.props.navigator.push({
title: 'New Page', title: 'New Page',
component: <InfoPage movie={this.state.dataSource.getRowData(0,index)}> </InfoPage> component: <InfoPage movie={this.props.dataSource.getRowData(0,index)}> </InfoPage>
}).bind(this); });
} }
renderLoadingView(){ renderLoadingView(){
if (this.state.isLoadingFail) { if (this.state.isLoadingFail) {
return ( return (
<TouchableOpacity onPress={() =>this.myfetchData.bind(this)} style={styles.container} > <TouchableOpacity onPress={() =>this.myfetchData()} style={styles.container} >
<View style={styles.container}> <View style={styles.container}>
<Text> <Text>
{'点击刷新'} {'点击刷新'}
@@ -141,7 +139,7 @@ export default class MyListView extends Component{
return ( return (
<View style={styles.container} key={rowID}> <View style={styles.container} key={rowID}>
<TouchableOpacity onPress={(rowID) =>this.pushInfo.bind(this)} style={styles.container} > <TouchableOpacity onPress={()=>{this.pushInfo(rowID)}} style={styles.container} >
<Image <Image
source={{uri: movie.imageurl}} source={{uri: movie.imageurl}}
style={styles.thumbnail}/> style={styles.thumbnail}/>
+3 -6
View File
@@ -39,10 +39,7 @@ export default class MyListViewDemo extends Component{
<Text style={styles.title}> <Text style={styles.title}>
随机 随机
</Text> </Text>
), )
event: function() {
this.fetchData();
}.bind(this)
} }
}) })
} }
@@ -59,7 +56,7 @@ export default class MyListViewDemo extends Component{
fetch(url) fetch(url)
.then((response) => response.json()) .then((response) => response.json())
.catch((error) => { .catch((error) => {
reject(err); reject(error);
}) })
.then((responseData) => { .then((responseData) => {
if(responseData){ if(responseData){
@@ -82,7 +79,7 @@ export default class MyListViewDemo extends Component{
<MyListView <MyListView
dataSource={this.state.dataSource} dataSource={this.state.dataSource}
refreshTitle={'测试一下刷新'} refreshTitle={'测试一下刷新'}
navigator={this.props.navigator} {...this.props}
fetchData={this.fetchData.bind(this)}/> fetchData={this.fetchData.bind(this)}/>
); );
} }
-1
View File
@@ -128,7 +128,6 @@ class TabBarNavigator extends Component {
}; };
} }
setNavItems(config) { setNavItems(config) {
console.log('setting nav items. currentTabIndex: ' + this.currentTabIndex);
if (this.currentRoute.isRoot) { if (this.currentRoute.isRoot) {
this.rootNavigatorItems[this.state.currentTabIndex] = config; this.rootNavigatorItems[this.state.currentTabIndex] = config;
this.forceUpdate(); this.forceUpdate();