1

我正在使用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}
                    />

当它应该引用 scrollView 时,console.log 会打印 object{},但不确定我可能遗漏了什么。这是设置表单本身的代码

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');
        }
    }
 }

};
4

1 回答 1

0

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

    <ScrollView style={styles.container} ref={(ref) => this.myScrollView = ref}>
于 2016-04-30T19:46:21.393 回答