alibaba / x-render

🚴‍♀️ 阿里 - 很易用的中后台「表单 / 表格 / 图表」解决方案
https://xrender.fun
7.05k stars 998 forks source link

setValueByPath 修改 list 下的属性不生效 #1400

Closed JoelynZhou closed 1 year ago

JoelynZhou commented 1 year ago

1.依赖仓库的版本(Dependencies versions):

react:18.2.0 form-render:2.2.15 antd:5.9.4 2.问题描述(Bug description): setValueByPath 修改 list 下的属性不生效

3.出现问题的 schema demo(Reproduction schema demo):

const watch = {
    select1: (val, index) => {
      console.log("val", val, index);
      form.setValueByPath("list[].input", val);
    }
  };

  const schema = {
    type: "object",
    displayType: "row",
    properties: {
      select1: {
        title: "输入框 A",
        type: "string"
      },
      select2: {
        title: "输入框 B",
        type: "string"
      },
      list: {
        title: "对象数组",
        type: "array",
        display: "inline",
        default: [{}],
        items: {
          type: "object",
          title: "基础信息",
          properties: {
            input: {
              title: "输入框",
              type: "string"
            }
          }
        }
      }
    }
  };

4.最小复现 demo(Reproduction demo): https://codesandbox.io/s/quizzical-sun-5pht34?file=/App.tsx:160-866

lhbxs commented 1 year ago

使用错误,form.setValueByPath('list', [])

lhbxs commented 1 year ago

"list[].input" 这种路径是错误的,你现在是在设置 list 的 里面的 value 值,而不是 schema。应该统一设置 form.setValueByPath('list', [])