这是我的情景。 使用GetObjectField组件我填充了一个TextInput,onFocus TextInput使用navigator push方法移动到另一个组件 我使用GenericSummary组件填充对象列表。当我选择对象的对象时 应该替换为GetObjectField TextInput
var GetObjectField = React.createClass({
getInitialState:function(){
return {textValue:""};
},
changeState:function(text){
var self=this;//here also i am getting text value but i am unable to do the setState
self.setState({textValue: text });
},
view:function(value){
this.changeState(value);//Here i am getting selected object value
}
render : function(){
return (<View>
<TextInput id={key} style={styles.textInput} value={this.state.textValue} placeholder="select object" onFocus={getDataFromDB.bind(this,this.view)} />
</View>)
}
})
function getDataFromDB(fillObject,ev){
var target=ev;
this.props.navigator.push({
id:'LookupComponent',
name:'LookupComponent',
fillObject : fillObject,
target:target,
})
}
var LookupComponent=React.createClass({
renderScene:function(route, navigator) {
var self=this
var target = this.props.target;
var fillObject=this.props.fillObject;
return (
<TouchableHighlight onPress={this.fillData.bind(this,item.value[refKey],fillObject, target,self.props.navigator)} underlayColor="#ffa456" navigator = {self.props.navigator}>
<View >
<GenericSummary record={item.value} recordId={item.id} org={self.props.org} navigator = {self.props.navigator}/>
</View>
</TouchableHighlight>)
},
render:function() {
return(<Navigator
renderScene={this.renderScene.bind(this)}
navigator={this.props.navigator}
navigationBar={
<Navigator.NavigationBar style={styles.navBarStyle} routeMapper={NavigationBarRouteMapperPopUp} />
} />)
}
})
function fillData(data,fillObject,nav,ev){
nav.pop();//when pop the component the getObjectField component is rerendering again
if(typeof fillObject != undefined){
fillObject(rowData,target,data);
}
}
答案 0 :(得分:1)
您可以在渲染场景方法中使用路径对象来传递有关您要导航的场景的额外信息,然后通过其道具将该额外信息传递到新场景。看起来您已经将fillObject传递给路径对象,因此您可以在下面的渲染方法中访问它。
renderScene(route, navigator) {
if (route.id === "LookupComponent") {
return (
<GenericSummary fillObject={route.fillObject} />
)
}
}