gpt4 book ai didi

javascript - onSubmitEditing 从不触发?

转载 作者:行者123 更新时间:2023-11-30 20:14:34 26 4
gpt4 key购买 nike

非常简单的问题,为什么当我在虚拟键盘上点击“搜索”时 onSubmitEditing 没有触发?

目前没有抛出任何错误,并且 onSearch() 中的 console.log 永远不会触发。

我正在使用 EXPO SDK v.29。

import React from 'react';
import { StyleSheet, Text, View, TextInput, ScrollView, Image } from 'react-native';
import { WebBrowser } from 'expo';
import Icon from 'react-native-vector-icons/Ionicons';

import Styles from 'app/constants/Styles';
import Vars from 'app/constants/Vars';

import Menu from 'app/components/Menu';
import MiniMap from 'app/components/MiniMap';

import NewsList from 'app/components/NewsList';

import {get, post} from 'app/helpers/api';


export default class HomeScreen extends React.Component {

static navigationOptions = ({ navigation }) => {
return {
headerTitle: (<Image style={{width: 132, height: 30}} source={require('./../../assets/images/header_image.png')}/>)
};
};

constructor(props) {
super(props);

this.state = {
menu: [],
loadingMenu: true,
searchString: '',
};
}

onMenuPress = (item) => {
let next;
let route = item.page_type.slice(4);

if(route == "PageExternal") {
WebBrowser.openBrowserAsync(item.page.url);
} else {

data = item.page;

if(item.children.length > 0) {
route = 'Menu';
data = item.children;
}

this.props.navigation.navigate(route, {
data: data,
title: item.title
});
}
}

onSearch = (e) => {
console.log('onSearch', e);
//WebBrowser.openBrowserAsync('https://www.1177.se/Halland/Sok/?q=Diabetes&submitted=true');
}

async componentDidMount() {

console.log('Eat my shorrs');
menuitems = await get('content/menu');

this.setState({
menu: menuitems,
loadingMenu: false,
})

//this._getMenu();
}

render() {

return (
<ScrollView style={Styles.whiteBackground}>
<View style={[Styles.blueBackground, Styles.topPadding, Styles.horizontalPadding]}>
<View style={[Styles.searchBox, Styles.bottomMargin]}>
<View style={Styles.searchField}>
<TextInput
style = {Styles.searchInput}
placeholder = "Sök sjukdom/behandling"
onSubmitEditing = {(e) => (this.onSearch(e))}
underlineColorAndroid = "transparent"
returnKeyLabel = "Sök på 1177"
returnKeyType = "search"
/>

<Icon style = {Styles.searchIcon} name = "ios-search" size={18}/>
</View>

<Text style={[Styles.searchLabel]}>Söksvaren kommer från 1177.se</Text>
</View>

<Menu
data={this.state.menu}
loading={this.state.loadingMenu}
style={Styles.topPadding}
onItemPress={this.onMenuPress}
/>
</View>

<Text style={[Styles.h1, Styles.blackText, Styles.horizontalPadding]}>Hitta till oss</Text>
<MiniMap navigation={this.props.navigation}></MiniMap>


<Text style={[Styles.h1, Styles.blackText, Styles.horizontalPadding]}>Nyheter</Text>
<NewsList navigation={this.props.navigation}></NewsList>

</ScrollView>
);
}
}

最佳答案

<TextInput
onSubmitEditing = {(event) => (this.onSearch(event.nativeEvent.text))}
multiline={false}
/>
  • 当指定 multiline={true} 时它不起作用,也许你的样式有那个。参见 Documentation
  • 您将使用 event.nativeEvent.text 找到您的文本

关于javascript - onSubmitEditing 从不触发?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52055391/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com