Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/406.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/react-native/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 在Submitediting上从不开火?_Javascript_React Native_Expo - Fatal编程技术网

Javascript 在Submitediting上从不开火?

Javascript 在Submitediting上从不开火?,javascript,react-native,expo,Javascript,React Native,Expo,非常简单的问题,为什么当我在虚拟键盘上点击“搜索”时,submitediting上的on不启动 目前没有抛出错误,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

非常简单的问题,为什么当我在虚拟键盘上点击“搜索”时,submitediting上的
on不启动

目前没有抛出错误,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>
        );
    }
}
从“React”导入React;
从“react native”导入{样式表、文本、视图、文本输入、滚动视图、图像};
从“expo”导入{WebBrowser};
从“反应本机矢量图标/离子图标”导入图标;
从“应用程序/常量/样式”导入样式;
从“app/constants/Vars”导入变量;
从“应用程序/组件/菜单”导入菜单;
从“应用程序/组件/小地图”导入小地图;
从“应用程序/组件/新闻列表”导入新闻列表;
从'app/helpers/api'导入{get,post};
导出默认类主屏幕扩展React.Component{
静态导航选项=({navigation})=>{
返回{
校长:()
};
};
建造师(道具){
超级(道具);
此.state={
菜单:[],
加载菜单:真,
搜索字符串:“”,
};
}
onMenuPress=(项目)=>{
让我们下一步;
让路线=项目.页面类型.切片(4);
如果(路由==“PageExternal”){
openBrowserAsync(item.page.url);
}否则{
数据=item.page;
如果(item.children.length>0){
路线='菜单';
数据=item.children;
}
这个.props.navigation.navigate(路线{
数据:数据,
标题:item.title
});
}
}
onSearch=(e)=>{
console.log('onSearch',e);
//WebBrowser.openBrowserAsync('https://www.1177.se/Halland/Sok/?q=Diabetes&submitted=true');
}
异步组件didmount(){
console.log('Eat my shorrs');
menuitems=等待获取(“内容/菜单”);
这是我的国家({
菜单:菜单项,
加载菜单:false,
})
//这个;
}
render(){
返回(
(this.onSearch(e))}
underlineColorAndroid=“透明”
returnKeyLabel=“Sök på1177”
returnKeyType=“搜索”
/>
Söksvaren kommer från 1177.se
Hitta till oss
尼赫特
);
}
}
尝试更改

onSubmitEditing = {(e) => (this.onSearch(e))}

(this.onSearch(event.nativeEvent.text))}
多行={false}
/>
  • 当指定了
    multiline={true}
    时,它就不起作用了,也许您的样式有这样的功能。请参见
  • 您将通过
    event.nativeEvent.text
然后保持

onSubmitEditing = {(e) => this.onSearch(e)}
如下图所示,尝试更改函数

function onSearch(e) {
    console.log('onSearch', e);
    //WebBrowser.openBrowserAsync('https://www.1177.se/Halland/Sok/?q=Diabetes&submitted=true');
}
希望这能奏效

看看这个

渲染方法

render() {
    return (
      <View style={styles.container}>
        <TextInput
          placeholder="Sök sjukdom/behandling"
          onSubmitEditing={this.onSearch}
          underlineColorAndroid="transparent"
          returnKeyLabel="Sök på 1177"
          returnKeyType="search"
          style={{ width: '100%', textAlign: 'center' }}
        />
      </View>
    );
}

@Khemraj不确定您的意思,serchInput是您在TextInput中键入的任何内容。我的意思是
样式。searchInput
您没有将事件处理程序绑定到
this
,您需要在构造函数中将其绑定到fireHi!不,多行是错误的。还尝试删除所有样式。同样的结果。。。它不会发射…当按下“完成”按钮时发射,希望你们也这样做。
function onSearch(e) {
    console.log('onSearch', e);
    //WebBrowser.openBrowserAsync('https://www.1177.se/Halland/Sok/?q=Diabetes&submitted=true');
}
render() {
    return (
      <View style={styles.container}>
        <TextInput
          placeholder="Sök sjukdom/behandling"
          onSubmitEditing={this.onSearch}
          underlineColorAndroid="transparent"
          returnKeyLabel="Sök på 1177"
          returnKeyType="search"
          style={{ width: '100%', textAlign: 'center' }}
        />
      </View>
    );
}
onSearch() {
  console.log('onSearch')
}