Android 我无法打印响应数据 构造函数(道具){ 超级(道具); 此.state={ 孤岛加载:是的, 搜索:“”, }; } componentDidMount(){ var url='url='; 获取(url) .then(response=>this.onResponse(response.data)); } onResponse(rdata){ 这是我的国家({ 孤岛加载:false, veri:rdata.data }); } 搜索数据(搜索){ this.setState({search}); var url='url='+搜索; 然后(response=>this.onResponse(response.data)); } 控制(){ if(this.state.search.length>3) { this.state.veri.map((userData)=>{ {userData.title} }); } } render() { if(此.state.isLoading){ 返回( ); } 返回( this.searchData(search)} 占位符=“欢迎”> {this.control()} ); }
我的数据是{[{}{}{}{}{}{}{}{}{}…]}。打印到console.log,但在render中,我无法打印文本。如何在渲染中以文本形式打印?在文本输入下,打印到{this.control()}它不起作用,打印到文本之间,但它不起作用。请帮助我:(确定,因此缺少两个Android 我无法打印响应数据 构造函数(道具){ 超级(道具); 此.state={ 孤岛加载:是的, 搜索:“”, }; } componentDidMount(){ var url='url='; 获取(url) .then(response=>this.onResponse(response.data)); } onResponse(rdata){ 这是我的国家({ 孤岛加载:false, veri:rdata.data }); } 搜索数据(搜索){ this.setState({search}); var url='url='+搜索; 然后(response=>this.onResponse(response.data)); } 控制(){ if(this.state.search.length>3) { this.state.veri.map((userData)=>{ {userData.title} }); } } render() { if(此.state.isLoading){ 返回( ); } 返回( this.searchData(search)} 占位符=“欢迎”> {this.control()} ); },android,ios,reactjs,react-native,Android,Ios,Reactjs,React Native,我的数据是{[{}{}{}{}{}{}{}{}{}…]}。打印到console.log,但在render中,我无法打印文本。如何在渲染中以文本形式打印?在文本输入下,打印到{this.control()}它不起作用,打印到文本之间,但它不起作用。请帮助我:(确定,因此缺少两个return: constructor(props) { super(props); this.state = { isLoading: true,
return
:
constructor(props) {
super(props);
this.state = {
isLoading: true,
search:'',
};
}
componentDidMount(){
var url = 'url=';
axios.get(url)
.then(response =>this.onResponse(response.data));
}
onResponse(rdata){
this.setState({
isLoading:false,
veri:rdata.data
});
}
searchData(search) {
this.setState({search});
var url = 'url='+search;
axios.get(url).then(response => this.onResponse(response.data));
}
control(){
if(this.state.search.length>3)
{
this.state.veri.map((userData) => {
<Text>{userData.title}</Text>
});
}
}
render()
{
if (this.state.isLoading) {
return (
<View style={{flex: 1, paddingTop: 20}}>
<ActivityIndicator />
</View>
);
}
return(
<View style={styles.container}>
<TextInput
style={{height: 40, borderColor: 'gray', borderWidth: 1}}
onChangeText = {(search) => this.searchData(search)}
placeholder="Welcome">
</TextInput>
{this.control()}
</View>
);
}
好的,因此缺少两个
return
:
constructor(props) {
super(props);
this.state = {
isLoading: true,
search:'',
};
}
componentDidMount(){
var url = 'url=';
axios.get(url)
.then(response =>this.onResponse(response.data));
}
onResponse(rdata){
this.setState({
isLoading:false,
veri:rdata.data
});
}
searchData(search) {
this.setState({search});
var url = 'url='+search;
axios.get(url).then(response => this.onResponse(response.data));
}
control(){
if(this.state.search.length>3)
{
this.state.veri.map((userData) => {
<Text>{userData.title}</Text>
});
}
}
render()
{
if (this.state.isLoading) {
return (
<View style={{flex: 1, paddingTop: 20}}>
<ActivityIndicator />
</View>
);
}
return(
<View style={styles.container}>
<TextInput
style={{height: 40, borderColor: 'gray', borderWidth: 1}}
onChangeText = {(search) => this.searchData(search)}
placeholder="Welcome">
</TextInput>
{this.control()}
</View>
);
}
更新您的代码并将其放在调用的位置
this.control()
m Update to code更新您的代码并将其放在调用的位置this.control()
m Update to code
control() {
if(this.state.search.length <= 3) return null; // mitigate the number of return by reverse the condition and return directly.
return this.state.veri.map((({title})) => <Text key={title}>{title}</Text>);
}