-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
不同层次字段之间的依赖的规则怎么写? #513
Comments
@jacks-sam1010 别人问的是用户端的解决方案,结果你上来就给个 fork 源码修改方案?而且你 fork 就算了,使用示例、测试用例都没有,人工智能创造垃圾污染社区? |
const data = util.libObj.mockjs.mock({
gender: '@pick(["male", "female"])',
id: '@id',
name: {
first: '@first',
last: '@last',
title(arg){
const { gender } = arg.context.root
return gender === 'male' ? 'Mr' : 'Ms';
}
}})
console.log(`data`, data) data {
gender: 'female',
id: '53250120200218657X',
name: { first: 'Jennifer', last: 'Walker', title: 'Ms' }
} |
谢谢。 |
mockjs 本身就可以的,使用上面的函数参数中即可获取 root。我上面是说如果你需要额外功能的话可以使用 mockm。 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
比如
这里我需要title根据gender来填。
如果写成
好像也不对,
this
只能取到同一层上的字段。有什么规则可以做到吗?
The text was updated successfully, but these errors were encountered: