跳转到内容

Record Schema 动态对象组

本文介绍 Piying-View 如何处理 v.record() 类型的动态键值对表单。

v.record(KeySchema, ValueSchema) 定义一个键为字符串、值为指定类型的对象。Piying-View 将 record 映射为特殊的 Group,键由用户动态添加:

fieldGlobalConfig.types 中确保 record 有对应的容器组件:

options = {
  fieldGlobalConfig: {
    types: {
      record: { type: PiyingViewGroup }, // 使用 Group 容器处理动态键
    },
  },
};

在表单场景中,Record 常用于:

用户可以动态添加键值对,如:{ "department": "研发部", "level": "P7" }

FieldFormConfig 提供 groupKeySchemagroupValueSchema,用于约束 Record 的键和值类型:

注意groupKeySchemagroupValueSchema 用于约束动态添加的键值对,而非替换原有的 record schema。

Record 字段的验证遵循标准 Group 规则:

当 Record 中某个值不满足验证条件时,该键对应的子字段标记为错误,但不影响其他键的值。