Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

多层嵌套对象验证规则怎么写? #323

Open
J1angyue opened this issue Nov 8, 2022 · 3 comments
Open

多层嵌套对象验证规则怎么写? #323

J1angyue opened this issue Nov 8, 2022 · 3 comments

Comments

@J1angyue
Copy link

J1angyue commented Nov 8, 2022

比如有以下对象,要验证c属性:
{ a: { b: { c: 'ccc' } } }
规则是这样写吗?不生效啊
a: { type: 'object', required: true, fields: { b: { type: 'object', required: true, fields: { c: { type: 'string', required: true } } } } }

@jswxwxf
Copy link

jswxwxf commented Nov 9, 2022

Same issue

@AllenYu0118
Copy link

@jswxwxf @J1angyue 我这边写是没问题的,试试参考这个最小实现,https://stackblitz.com/edit/typescript-7dtq2r?file=nest.ts

@BoBoooooo
Copy link

请问是否支持 这样的嵌套path定义?

const rules = {
  'a.b.c': [
    { required: true, message: 'a.b.c is required' },
    { type: 'string', message: 'a.b.c must be a string' },
  ],
};

const data = {
	a: {
		b: {
			c: '123'
		}
	}
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants