【发布时间】:2019-03-08 12:40:58
【问题描述】:
我想执行 if 语句中的所有行但我不能
这是我的代码
import React, { Component } from 'react';
import { Text, View } from 'react-native';
class test extends Component {
constructor() {
super();
this.state = { data: [] };
}
testFunction = () => {
return (
<View>
<Text>Anything</Text>
</View>
);
};
render() {
return (
<View>{data.length > 0 ? <Text>Hi</Text> : this.testFunction() <Text>Hello</Text>}</View>
);
}
}
export default test;
我想执行 (this.testFunction()) 和 (<Text>Hello</Text>)
谢谢
【问题讨论】:
-
请提供您的完整组件代码
-
import React, { Component } from 'react'; import { Text, View} from 'react-native'; class test extends Component { constructor() { super(); this.state = { data: [], }} testFunction = () => { return ( <View><Text>Anything</Text></View> ) }render() { return ( <View> {data.length > 0 ? <Text>Hi</Text> : this.testFunction() <Text>Hello</Text> } </View> );} } export default test;
标签: reactjs react-native if-statement