我正在学习ReactNative.Navigator.renderScene道具。在路线可变可以从React Component Prop中调用类对象吗?
'use strict';
import React,{Component} from 'react';
import ReactNative from 'react-native';
const {
TouchableHighlight,
Navigator,
AppRegistry,
Text,
View,
} = ReactNative;
class TestClass extends Component{
render(){
return <Text>test</Text>
}
}
class MyTag extends Component{
render(){
return <Text>test</Text>
}
}
class Main extends Component{
render(){
const routes =[{component:TestClass,index:0},{component:MyTag,index:1}]
return(
<Navigator
initialRoute={routes[0]}
initialRouteStack={routes}
renderScene={(route, navigator) =>
<View><TouchableHighlight onPress={() => {
if (route.index === 0) {
navigator.push(routes[1]);
} else {
navigator.pop();
}
}}><View>{route.component}</View>
</TouchableHighlight></View>
}
/>
)
}
}
AppRegistry.registerComponent('ChoiceComponent',() => Main);
制罐部件通过使用renderScene道具{route.component}在JSX称为?
如果{route.component}更改为<测试类/ >,则TestClass被正确调用。
它的工作! 我重读了React官方文档,发现{}中包含的JavaScript对象是文本或函数,并未按照我的方式使用。 正如你所说,我将从现在开始使用大写的标识符。 非常感谢! – user2255716
@ user2255716:很高兴帮助。我不确定你的意思是什么*“我发现包含在{}中的javascript对象是文本或函数,而不是用我的方式。”*该表达式可能导致任何结果,并且*被使用... –