【问题标题】:Accessing ref with the onFocus callback while using tcomb-form-native使用 tcomb-form-native 时使用 onFocus 回调访问 ref
【发布时间】:2016-04-30 18:59:29
【问题描述】:

我正在使用https://github.com/gcanti/tcomb-form-native &这是代码的sn-p

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

};

【问题讨论】:

    标签: react-native ref tcomb


    【解决方案1】:

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-09-29
      • 2017-04-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多