函数上下文

在配置响应器时,我们会看到边上有个案例区(Example),其中写道:

  1. /**
  2. * You can use the built-in context variables
  3. *
  4. * 1. `$self` is the current Field Model
  5. *
  6. * 2. `$form` is the current Form Model
  7. *
  8. * 3. `$deps` is the dependencies value
  9. *
  10. * 4. `$observable` function is used to create an persistent observable state object
  11. *
  12. * 5. `$memo` function is is used to create a persistent data
  13. *
  14. * 6. `$effect` function is used to handle side-effect logic
  15. *
  16. * 7. `$props` function is used to set component props to current field
  17. *
  18. * Document Links
  19. *
  20. * 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
  21. **/

这里做下翻译:

  1. $self 对象类型,存储了当前字段模型
  2. $form 对象类型,存储了当前表单模型
  3. $deps 数组类型,存储了当前字段的“依赖字段”,对应“配置响应器”弹窗最上面的“依赖字段”。
  4. $observable 函数类型,用于创建一个持久的可观察状态对象
  5. $memo 函数类型,用于创建持久化数据
  6. $effect 函数类型,用于处理副作用逻辑
  7. $props 函数类型,它的参数将会直接穿透给组件
    • 比如用antd的组件制作了designable中的物料,通常会把组件的参数对接成“属性面板”中的配置
    • 如果“属性面板”的配置参数有遗漏,可以通过$props穿透给antd组件,做补位。

常用语句

取其它组件的值

  1. 给其它组件设置“字段标识”,比如设置为abc
  2. 那么在配置响应器的高代码编辑区,可通过$form.values.abc获取到它