We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
因为项目居于backbone开发的,所以关于backbone.Collection的mock数据比较头疼。
[ { ... }, { ... } ... ]
目前mock似乎不支持上面数据结构的输出格式,只能手动一条一条添加,还是说我不知道?
想了下,可以换种方法:
var data = mock.mock({'data|5-10': [{ ... }]}); mock.mock(/url/, data.data);
The text was updated successfully, but these errors were encountered:
目前不支持直接返回数组。 你所描述的这种场景也挺常见,受你的启发,Mock.js 接下来会考虑要不要增加一个新的方法签名 Mock.mock(template, regulation),例如:
Mock.mock([{ ... }], '5-10')
在实现上,会接近于现在的内部方法 Handle.gen(template, name, obj),或者仅仅是把该内部方法暴露出来。
如果你有更合适的方法签名或实现,非常欢迎提供建议和贡献代码。
另外,参考下我最初的想法: 属性名 data|5-10 定义了生成数据时的规则,所以是必须的。从接口是否易读易用的角度看,如果希望直接传入数据模板 [{ ... }],那么,生成数据所需的规则势必需要通过其他参数传入,反而不如直接定义在属性名中直观。
data|5-10
[{ ... }]
Sorry, something went wrong.
Mock.mock(template, regulation)
由于 regulation 的格式和可选值太多,在使用这个方法签名时会导致混乱,目前不考虑支持。
regulation
nuysoft
No branches or pull requests
因为项目居于backbone开发的,所以关于backbone.Collection的mock数据比较头疼。
目前mock似乎不支持上面数据结构的输出格式,只能手动一条一条添加,还是说我不知道?
想了下,可以换种方法:
The text was updated successfully, but these errors were encountered: