函数上下文
在配置响应器时,我们会看到边上有个案例区(Example),其中写道:
/**
* You can use the built-in context variables
*
* 1. `$self` is the current Field Model
*
* 2. `$form` is the current Form Model
*
* 3. `$deps` is the dependencies value
*
* 4. `$observable` function is used to create an persistent observable state object
*
* 5. `$memo` function is is used to create a persistent data
*
* 6. `$effect` function is used to handle side-effect logic
*
* 7. `$props` function is used to set component props to current field
*
* Document Links
*
* https://react.formilyjs.org/api/shared/schema#%E5%86%85%E7%BD%AE%E8%A1%A8%E8%BE%BE%E5%BC%8F%E4%BD%9C%E7%94%A8%E5%9F%9F
**/
这里做下翻译:
$self
对象类型,存储了当前字段模型$form
对象类型,存储了当前表单模型$deps
数组类型,存储了当前字段的“依赖字段”,对应“配置响应器”弹窗最上面的“依赖字段”。$observable
函数类型,用于创建一个持久的可观察状态对象$memo
函数类型,用于创建持久化数据$effect
函数类型,用于处理副作用逻辑$props
函数类型,它的参数将会直接穿透给组件- 比如用antd的组件制作了designable中的物料,通常会把组件的参数对接成“属性面板”中的配置
- 如果“属性面板”的配置参数有遗漏,可以通过
$props
穿透给antd组件,做补位。
常用语句
取其它组件的值
- 给其它组件设置“字段标识”,比如设置为
abc
- 那么在配置响应器的高代码编辑区,可通过
$form.values.abc
获取到它