reactjs - 制服:创建自定义字段
问题描述
我定义了以下简单模式:
import SimpleSchema from 'simpl-schema';
export const Comments = new Mongo.Collection("comments");
export const CommentsSchema = new SimpleSchema({
comments: Array,
"comments.$": Object,
"comments.$.author": String
"comments.$.text": String
})
我有一个组件AutoForm
可以查看/编辑这个评论数组:
import {ErrorsField, SubmitField, ListField} from "uniforms-semantic";
import AutoForm from 'uniforms-semantic/AutoForm';
<AutoForm schema={CommentsSchema} onSubmit={comments => this.updateRequest(comments)} model={this.props.comments}>
<ListField name={"comments"}/>
<ErrorsField/>
<SubmitField/>
</AutoForm>
this.updateRequest(...)
是一个调用 Meteor 后端函数来更新 Mongo 集合的函数。
我想自定义ListField
,以便对于每个评论,"comments.$.text"
TextField 显示为允许换行符的更大文本框。
我考虑过重写一个自定义版本,ListField
但对于像这样的小改动来说,这似乎是不必要的复杂。使用制服 API 添加这样的小自定义的最佳方法是什么?
解决方案
查看文档,您似乎可以指定 ListField 的内部工作方式。这是未经测试的,但我会猜测以下内容:
<ListField name="comments">
<ListItemField name="$">
<NestField name="">
<TextField name="author" />
<LongTextField name="text" />
</NestField>
</ListItemField>
</ListField>
https://github.com/vazco/uniforms/blob/master/INTRODUCTION.md#props-propagation
推荐阅读
- sql - 无法设置 Percent_rank() - 默认为 0.0
- swift - Realm (Swift):迁移期间如何获取 MutableSet 数据?
- view - 雪花的物化视图
- ios - 用多行更改 UIMenu 标题(带有 UIButton 的 UIMenu)
- chef-infra - 在厨师食谱中编写循环的最佳实践是什么?
- python - Kivy 文字转语音
- azure-active-directory - 使用 C# 为 SPFX SSO Azure AD 生成访问令牌而不提示用户(自动)
- bash - 在 ubuntu 终端或 bash 脚本中使用系统参数运行 Matlab 脚本
- python - 将函数传递给多处理池中的地图或星图
- html - SCSS 文件在 index.html 实时服务器上不起作用