如何创建 CallBack 方法以从另一个 JS 获取值? [英] How to create CallBack method to get value from another JS?
问题描述
我已经为 datePicker 创建了 CustomDatePicker.JS
文件,对于 Android 使用 DatePickerAndroid
,对于 ios 使用 DatePickerIOS
,它在我的另一个 Profile.js
文件.我使用如下.
I have create CustomDatePicker.JS
file for datePicker, for Android use the DatePickerAndroid
and for ios use DatePickerIOS
, and its use in my another Profile.js
file. I use like below.
<CustomDatePicker ref='modal'></CustomDatePicker>
现在无论何时选择日期,CustomDatePicker.JS
类都会获取该值,但我想要Profile.js
中的日期值.那么如何在配置文件中获取日期值.
Now whenever will select the date, CustomDatePicker.JS
class get the value but I want to the date value in Profile.js
. So how can get date value in profile.
CustomDatePicker.JS
:这里将获取日期和时间日志.Profile.js
:想要在 CustomDatePicker 上选择日期.
CustomDatePicker.JS
: Here Will get date and time log.
Profile.js
: Want to date which is selected on CustomDatePicker.
我希望你能理解...
谢谢.
推荐答案
在您的 Profile.js
,即 Profile 组件
中,您可以传递一些回调 fn 作为道具,例如,
In your Profile.js
, i.e Profile component
you can pass some callback fn as props like,
<CustomDatePicker
mode="date"
onDateChange={date => this.onDateChange(date)}
ref='modal'>
</CustomDatePicker>
在你的 CustomDatePicker.js
,即你定义了 DatePickerIOS
的 CustomDatePicker 组件
,你可以使用这些道具.
In you CustomDatePicker.js
, i.e CustomDatePicker component
where you have defined DatePickerIOS
, you can use those props.
<DatePickerIOS
{...this.props}
/>
这篇关于如何创建 CallBack 方法以从另一个 JS 获取值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!