【发布时间】:2019-02-14 21:38:04
【问题描述】:
我尝试了我在网上看到的所有内容,但没有一个能解决我的问题。 它总是给我“无法读取未定义的属性'导航'。
我该如何解决这个问题?
我将信息从第 1 页发送到页眉,但我无法从页眉发送到第 1 页。以及如何从标题转到第 1 页我的意思是如何通过单击某些按钮打开第 1 页
import React, { Component } from 'react';
import { View, Text, FlatList } from 'react-native';
import { YellowBox } from 'react-native';
YellowBox.ignoreWarnings(['Remote debugger']);
export default class Header extends Component {
constructor(props){
super(props);
}
render() {
console.warn(this.props.navigation);
return (
<View style= {styles.headerStyle}>
<View style= {[styles.View2, {backgroundColor: 'rgba(116,185,255,0.3)'}]} >
<Text style={[styles.childText, {color:'#74b9ff'}]} >{this.props.color1}</Text>
</View>
<View style= {[styles.View2, {backgroundColor: 'rgba(255,234,167,0.3)'}]}>
<Text style={[styles.childText, {color:'#ffeaa7'}]} >{this.props.color2}</Text>
</View>
<View style= {[styles.View2, {backgroundColor: 'rgba(204,255,204,0.3)'}]}>
<Text style={[styles.childText, {color:'#ccffcc'}]} >0</Text>
</View>
<View style= {[styles.View2, {backgroundColor: 'rgba(255,128,128,0.3)'}]}>
<Text style={[styles.childText, {color:'#ff8080'}]} >0</Text>
</View>
<View style= {[styles.View2, {backgroundColor: 'rgba(207,207,176,0.3)'}]}>
<Text style={[styles.childText, {color:'rgba(207,207,176,0.3)'}]} >0</Text>
</View>
</View>
);
};
}
这是我使用页眉组件的第 1 页。
import React, { Component } from 'react';
import { View, Text, FlatList, Image, ScrollView} from 'react-native';
import DOMParser from 'react-native-html-parser';
import axios from 'axios';
import Header from './Header';
import Bar from './Bar';
import Footer from './Footer';
const Blue = [];
const Yellow = [];
export default class Page1 extends Component {
state = {
leader: []
}
componentWillMount() {
fetch('url')
.then(response => {
if (response.ok) {
return response;
}else {
let error = new Error('Error ');
error.response = response;
throw error;
}
},
error => {
let errmess = new Error(error.message);
throw errmess;
})
.then(response => response.text())
.then(leaders => {
const str = leaders.substring(76);
const str2 = str.substring(0, str.length - 9);
const x = JSON.parse(str2);
this.setState({ leader: x });
})
.catch(error => {
this.setState({ errMessage: error.message });
});
}
renderall() {
return this.state.leader.map(alb =>
<View style={styles.container} key= {alb.Ref}>
<Text style={[styles.textStyle, {marginLeft:'5%'}]}> {alb.Tescil_No} </Text>
<Text style={[styles.textStyle, {marginLeft:'6%'}]}> {alb.GumrukAdi} </Text>
<Text style={[styles.textStyle, { marginLeft:'5%'}]}> {alb.ACIKLAMA} </Text>
</View>
)
}
count(){
return this.state.leader.map(color => {
if(color.Renk == 'MAVI'){
Blue.push("MAVI");
}
else if(color.Renk == 'SARI')
{
Yellow.push("SARI")
}
})
}
render() {
this.count();
console.log(Blue.length);
console.log(this.state.leader);
return (
<View style= {styles.firstView}>
<View style={{flex: 1.5}}>
<Header color1 = {Blue.length} color2 = {Yellow.length}/>
</View >
<View style={{flex: 0.5, backgroundColor:'#f2f2f2'}}>
<Bar />
</View>
<View style={{flex: 9}}>
<ScrollView>
{this.renderall()}
</ScrollView>
</View>
<View style={styles.footerStyle}>
<Footer />
</View>
</View>
);
}
【问题讨论】:
-
你是如何使用你的标题的?你能展示一下代码吗?
-
@Andrew 我想通过文本的 onpress 进入下一页。所以我不应该使用导航吗?
-
你是在使用 redux 还是只是将 props 从一个组件传递到另一个组件?
-
你在我的代码中看到“
" 我用 this.props.color1 获取数据。我想将这个类的值传递给另一个我获取数据“this.props.color1”的类{this.props.color1} -
我还想从这个页面转到另一个页面。可以帮我解决这两个问题