点击一个按钮不会显示
问题描述:
我开发的一个应用程序的WebView反应母语,我面临一个问题:点击一个按钮不会显示
我想,当我点击一个按钮(或者直接查看按钮所在的位置)WebView将显示在屏幕上,并打开直接传入参数的链接。 但没有任何反应。
这里是我的代码:
return (
<ScrollView style={[style.case1]} refreshControl={<RefreshControl refreshing={this.state.refreshing} onRefresh={this.handleRefresh} />} >
{
this.state.orders.map(function (order) {
let a = _this.getPosts(order);
let Final = _this.splitString(a.message," ");
return (
<View style={[style.case2]} key={a.message} >
<Couleur couleur={Final[4]} />
<Text style={[style.Nom]} >Nom : {Final[1]}</Text>
<Text style={[style.Nom]} >Numéro de build : {Final[2]}</Text>
<Button onPress={<Web url={Final[3]} />} title="Click"/>
</View>
);
})}
</ScrollView>
);
而且网页视图类:
import React, {Component} from "react";
import {WebView} from "react-native";
export default class Web extends Component {
constructor(props){
super(props);
}
render() {
let uri = this.props.url;
return(
<WebView
ref={(ref) => {this.webview = ref;}}
source={{uri}}
style={{marginTop:20}}
/>
)
}
}
,我得到这个错误:
“对象不是一个函数(计算“这个.props.onPress(e)')
如果有人帮助我,我会很开心! :)
答
onPress操作需要是一个可以执行某些操作的函数。现在,您正在将操作设置为组件,并且反应不知道该如何处理。
没有某种控制视图的导航库,你可以做一些事情,比如让onPress设置一些控制渲染函数的一部分的状态,它显示你现有的页面或新的'Web'组件。
因此,请onPress,如: onPress={e => this.setState({showWebPart:true})}
然后在你当前的渲染功能,你可以有一个像三元:
{this.state.showWebPart ? <Web url={Final[3]} /> : ..current render stuff}
有你试图改变这样的'onPress = {()=>收益 }'? –
我输入解决方案时出错,但如果我删除'返回',我现在没有任何错误。 –
但是我仍然没有显示WebView。感谢您的帮助 –