是否有可能使meteor-autoformmeteor-collection2-corereact-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),或者为此使用其他库。我在最近的项目github.com/nicolaslopezj/simple-react-form中使用了它。它功能强大,但是比神奇的Autoform(您必须编写自己的表单和字段组件)要“动手”得多。

10-07 17:42