vue-vben-admin icon indicating copy to clipboard operation
vue-vben-admin copied to clipboard

动态生成schema数组,updateSchema为何不生效

Open ITKing80 opened this issue 3 years ago • 2 comments

Discussed in https://github.com/anncwb/vue-vben-admin/discussions/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>

ITKing80 avatar Dec 20 '21 10:12 ITKing80

经跟踪源代码,这位同学好像说的不对,不能增加新控件,是不是有BUG? image WJ~JG27S~(0Y$59EE8$HW 9

ITKing80 avatar Dec 21 '21 01:12 ITKing80

This issue is stale because it has been open 60 days with no activity. Remove stale label or comment or this will be closed in 7 days

anncwb avatar May 04 '24 01:05 anncwb