使用 Meteor React 和 Simple-Schema 自动形成
Autoform with Meteor React and Simple-Schema
有没有可能meteor-autoform work with meteor-collection2-core and react-meteor?
MWE
最好我想要这样的东西。
./imports/api/Books.js
import { Mongo } from 'meteor/mongo';
import SimpleSchema from 'simpl-schema';
const Books = new Mongo.Collection("books");
Books.attachSchema(new SimpleSchema({
title: {
type: String,
label: "Title",
max: 200
},
author: {
type: String,
label: "Author"
},
}));
if (Meteor.isServer) {
Meteor.publish('allBooks', function () {
return Books.find({}, );
});
};
export default Books;
./imports/client/NewBooks.js
import React, { Component, PropTypes } from 'react';
import { createContainer } from 'meteor/react-meteor-data';
import { quickForm } from 'meteor-autoform';
import Books from '../api/Books';
class NewBooks extends Component {
constructor(props) {
super(props)
this.state = {}
}
render() {
return (
<div className="container">
<quickForm
collection={Books}
id="insertBookForm"
type="insert">
</quickForm>
</div>
)
}
};
export default createContainer(() => {
Meteor.subscribe('allBooks');
return {
books: Books.find().fetch()
}
}, NewBooks);
据我所知,Autoform 严重依赖于 Blaze,因此,您可以在 React 中使用 blaze autoform 组件(参见 here), or you can use a different library for this. I used this in a recent project: github.com/nicolaslopezj/simple-react-form。它功能强大,但 'hands-on' 比神奇的 Autoform (您必须编写自己的表单和字段组件)。
npm 包 Uniforms 与 Bootstrap 配合使用超级简单。
除了./imports/client/NewBooks.js
import AutoForm from 'uniforms-unstyled/AutoForm';
...
<AutoForm
schema={Books._collection.simpleSchema()}
onSubmit={doc => console.log(doc)}
/>
有没有可能meteor-autoform work with meteor-collection2-core and react-meteor?
MWE
最好我想要这样的东西。
./imports/api/Books.js
import { Mongo } from 'meteor/mongo';
import SimpleSchema from 'simpl-schema';
const Books = new Mongo.Collection("books");
Books.attachSchema(new SimpleSchema({
title: {
type: String,
label: "Title",
max: 200
},
author: {
type: String,
label: "Author"
},
}));
if (Meteor.isServer) {
Meteor.publish('allBooks', function () {
return Books.find({}, );
});
};
export default Books;
./imports/client/NewBooks.js
import React, { Component, PropTypes } from 'react';
import { createContainer } from 'meteor/react-meteor-data';
import { quickForm } from 'meteor-autoform';
import Books from '../api/Books';
class NewBooks extends Component {
constructor(props) {
super(props)
this.state = {}
}
render() {
return (
<div className="container">
<quickForm
collection={Books}
id="insertBookForm"
type="insert">
</quickForm>
</div>
)
}
};
export default createContainer(() => {
Meteor.subscribe('allBooks');
return {
books: Books.find().fetch()
}
}, NewBooks);
据我所知,Autoform 严重依赖于 Blaze,因此,您可以在 React 中使用 blaze autoform 组件(参见 here), or you can use a different library for this. I used this in a recent project: github.com/nicolaslopezj/simple-react-form。它功能强大,但 'hands-on' 比神奇的 Autoform (您必须编写自己的表单和字段组件)。
npm 包 Uniforms 与 Bootstrap 配合使用超级简单。
除了./imports/client/NewBooks.js
import AutoForm from 'uniforms-unstyled/AutoForm';
...
<AutoForm
schema={Books._collection.simpleSchema()}
onSubmit={doc => console.log(doc)}
/>