react-native中TextInput的onBlur事件中的问题

时间:2016-02-15 07:37:40

标签: react-native

我想在按下“Do Some Work”按钮但是在调用任何一个重点TextInput的onBlur事件之后做一些任务。

以下是我的示例代码: -

    spinner.setItems("Daily", "One time", "Frequency"); // here "Frequency is the hint text"
    spinner.setSelectedIndex(2);

    spinner.setOnItemSelectedListener(new OnItemSelectedListener() {
        @Override
        public void onItemSelected(Spinner view, int position, long id, Object item) {
            if (position != 2) {
                view.setItems("Daily", "One time");
                view.setSelectedIndex(position);
            }else {
                // This item is not a valid selection
            }
        }
    });

我试过打电话

'use strict';
var React = require('react-native');
var {AppRegistry,View,Text,ScrollView,TextInput,TouchableOpacity} = React;

var MyApp = React.createClass({
    doSomeWork: function () {
        console.log("doSomeWork called....");

    },
    render: function () {
        return (
            <View>
                <TouchableOpacity style={{padding:10,alignItems:"center",backgroundColor:"blue"}}
                                  onPress={this.doSomeWork}>
                    <Text>Do Some Work</Text>
                </TouchableOpacity>
                <View style={{height:400}}>
                    <ScrollView keyboardShouldPersistTaps={true}>
                        <View>
                            <TextInput ref="first" onBlur={()=>{console.log("TextInput 1 blurred....")}}/>
                        </View>
                        <View>
                            <TextInput ref="second" onBlur={()=>{console.log("TextInput 2 blurred....")}}/>
                        </View>
                        <View>
                            <TextInput ref="third" onBlur={()=>{console.log("TextInput 3 blurred....")}}/>
                        </View>
                    </ScrollView>

                </View>
            </View>
        );
    }
});
AppRegistry.registerComponent('nativeApp', () => MyApp);

手动,但这是异步的,我不知道TextInput的事件是否已经调用。

任何帮助将不胜感激。

0 个答案:

没有答案