-
需求想要在页面配置下拉框的选项,所以需要在页面同时展示下拉框与表格。修改表格数据,同步修改下拉框下拉选项。 问题数据变化 Select.options 未刷新,一开始以为是自己 上代码https://codesandbox.io/s/young-dream-99z9n?file=/App.tsx 关键代码// 以下是部分代码,主要说明 “x-reactions” 的用法,完整代码看上方 codesandbox 链接。
const schema = {
type: "object",
properties: {
tableItems: {
type: "boolean",
title: "下拉选项依赖下表",
"x-decorator": "FormItem",
"x-component": "Select"
"x-reactions": {
// 1、由于此字段依赖 `array` 字段的结果,所以这里用 `dependencies`
// 此处 x-reactions 与 下面 2 任写一个都满足结果。
dependencies: ["array"],
fulfill: {
state: {
dataSource: "{{JSON.parse(JSON.stringify($deps[0] || []))}}"
}
}
}
},
array: {
type: "array",
"x-decorator": "FormItem",
"x-component": "ArrayTable",
// "x-reactions": {
// // 2、此处如果不写条件,"array" 任何变化都会执行下方语句。
// // $form.setFieldState 属于主动联动模式的一种
// fulfill: {
// // 这里纯是为了打印看 dataSource 的值
// run:
// "console.log($form.getFieldState('tableItems').dataSource);" +
// "$form.setFieldState('tableItems',(state)=>state.dataSource = JSON.parse(JSON.stringify($self.value || [])) )"
// }
}
}
}结果看打印数据,其实 select.dataSource 已经变化了,但是页面没有刷新。开始以为是 问题原因据作者解答
结论@janryWang 像这种情况,我是只能去改 antd 的代码了吗?或者有什么其他的巧妙的方法可以实现我的需求吗? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 4 replies
-
|
可以给antd提个bug |
Beta Was this translation helpful? Give feedback.
-
|
该问题是formily的问题,目前最新版已经修复了 |
Beta Was this translation helpful? Give feedback.

该问题是formily的问题,目前最新版已经修复了