繁体   English   中英

使用tcomb-form-native时使用onFocus回调访问ref

[英]Accessing ref with the onFocus callback while using tcomb-form-native

我正在使用https://github.com/gcanti/tcomb-form-native&这里是代码片段

_renderScene(route, navigator) {
        var Cook_time = {
        onFocus: () => {
            console.log('cook time has focus');
            console.log(this.refs);
        },
    };

    options.fields['Cook_time'] = Cook_time;


    return (
        <View style={{ flex: 1 }}>
            <ScrollView style={styles.container} ref="scrollView">

                <Form
                    ref="form"
                    type={Recipe}
                    options={options}
                    onChange={this.onChange}
                    onFocus={this.onChange}
                    />

console.log在应该引用scrollView时打印对象{},不知道我可能缺少什么。 这是设置表单本身的代码

var Recipe = t.struct({
 Recipe_name: t.String,
 yield: t.maybe(t.String),
 Prep_time: t.maybe(t.String),
 Cook_time: t.maybe(t.String),
 source: t.maybe(t.String),
})

var options = {
 fields: {
    yield: {
        label: 'Yield',
    },
    Prep_time: {
        label: 'Preparation time',
    },

    source: {
        label: 'Source',
        placeholder: 'family, friends, website ...',
        onFocus: function () {
            console.log('source has focus');
        }
    }
 }

};

ref属性是一个回调,根据react-native文档,我需要做的就是保存一个引用

    <ScrollView style={styles.container} ref={(ref) => this.myScrollView = ref}>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM