vue-vben-admin 动态生成schema数组,updateSchema为何不生效

ippsafx7  于 2023-03-19  发布在  其他
关注(0)|答案(1)|浏览(978)

Discussed in #1512

Originally posted by ITKing80 December 20, 2021
调用以下方法,界面没有出现新的控件,我哪里用的不对吗?
另外有两个问题:
1、required和max同时校验时,长度超过后提示必填
2、我用append是可以一个一个添加的,但是设置defaultValue无效?

async function getHxGroup() {
    const formSchemas: FormSchema[] = [];
    let hxGroupList: HxGroupList = (await getHxGroupList()) as HxGroupList;    //调用接口获取要生成的控件个数及值
    if (hxGroupList.hxGroups != null) {
      hxGroupList.hxGroups.forEach((o, i) => {
        formSchemas.push(
          {
            field: `hxGroupName${i}`,
            component: 'Input',
            label: `分组(${i + 1})名称`,
            defaultValue: o.hxGroup,
            colProps: {
              span: 8,
            },
            rules: [{ type: 'string', max: 20, required: true }], //required和max同时校验时,长度超过后提示必填
          },
          //'',
        );

        //添加select控件
        formSchemas.push(
          {
            field: `selectHX${i}`,
            component: 'Select',
            label: '选项',
            slot: 'selectHX',
            defaultValue: o.groupDetail,
            colProps: {
              span: 8,
            },
            required: true,
          },
        );

        //添加+-控件
        formSchemas.push(
          {
            field: `${i}`,
            component: 'Input',
            label: ' ',
            colProps: {
              span: 8,
            },
            slot: 'add',
          },
        );

        //添加选项
        o.groupDetail.forEach((d) => {
          options.value.push({ label: d, value: d });
        });
      });
    }

    debugger;
    updateSchema(formSchemas);
    return hxGroupList;
  }</div>
ctzwtxfj

ctzwtxfj1#

经跟踪源代码,这位同学好像说的不对,不能增加新控件,是不是有BUG?

相关问题