2016-07-14 19 views
0

Ich habe damit ein paar Wochen gekämpft. Ich möchte meteor-react-autoform in meiner Webseite verwenden. Ich benutze Base von The Meteor Chef. Jede Hilfe wird wirklich geschätztMeteor-react-autoform zeigt nichts

Sorry für das schlechte Englisch, hier sind die Dateien.

Dies ist die Datei, wo ich mein Schema und Sammlung definieren:

import { Mongo } from 'meteor/mongo'; 
import { SimpleSchema } from 'meteor/aldeed:simple-schema'; 
import { Factory } from 'meteor/dburles:factory'; 

export const Documents = new Mongo.Collection('Documents'); 

// Documentation -> https://github.com/MechJosh0/meteor-react-autoform 
// Extend the schema to allow our materialForm object 
SimpleSchema.extendOptions({ 
    materialForm: Match.Optional(Object) 
}); 


Documents.allow({ 
    insert:() => false, 
    update:() => false, 
    remove:() => false 
}); 

Documents.deny({ 
    insert:() => true, 
    update:() => true, 
    remove:() => true 
}); 

Documents.schema = new SimpleSchema({ 
    title: { 
    type: String, 
     materialForm: { 
      floatingLabelText: 'Your name', 
      hintText: 'Sarah Smith...' 
    } 
    } 
}); 

Documents.attachSchema(Documents.schema); 

Hier ist die Form und den Insert-Handler

import React from 'react'; 
import { Bert } from 'meteor/themeteorchef:bert'; 
import { insertDocument } from '../../api/documents/methods.js'; 
import ReactAutoForm from 'meteor-react-autoform'; 
import { Documents } from '../../api/documents/documents'; 


const handleInsertDocument = (event) => { 
    const target = event.target; 
    const title = target.value.trim(); 

    if (title !== '' && event.keyCode === 13) { 
    insertDocument.call({ 
     title 
    }, (error) => { 
     if (error) { 
     Bert.alert(error.reason, 'danger'); 
     } else { 
     target.value = ''; 
     Bert.alert('Document added!', 'success'); 
     } 
    }); 
    } 
}; 


export const AddDocument =() => (
    <ReactAutoForm 
     muiTheme={true} 
     onSubmit={handleInsertDocument} 
     schema={Documents.schema} 
     type="insert" 
    /> 
); 

Dies ist die Datei mit der Methode definiert:

import { Documents } from './documents'; 
import { SimpleSchema } from 'meteor/aldeed:simple-schema'; 
import { ValidatedMethod } from 'meteor/mdg:validated-method'; 

export const insertDocument = new ValidatedMethod({ 
    name: 'documents.insert', 
    validate: new SimpleSchema({ 
    title: { type: String } 
    }).validator(), 
    run(document) { 
    Documents.insert(document); 
    } 
}); 

export const updateDocument = new ValidatedMethod({ 
    name: 'documents.update', 
    validate: new SimpleSchema({ 
    _id: { type: String }, 
    'update.title': { type: String, optional: true } 
    }).validator(), 
    run({ _id, update }) { 
    Documents.update(_id, { $set: update }); 
    } 
}); 

export const removeDocument = new ValidatedMethod({ 
    name: 'documents.remove', 
    validate: new SimpleSchema({ 
    _id: { type: String } 
    }).validator(), 
    run({ _id }) { 
    Documents.remove(_id); 
    } 
}); 

Antwort

0

Ihre Sammlung und das Schema müssen separat in verschiedenen Dateien definiert werden. Verschieben Sie Ihr Schema in eine neue Datei, importieren Sie das Schema in Ihre Sammlungsdatei und übertragen Sie es über SimeplSchema und speichern Sie es als Sammlung. Dann importieren Sie in der Reaktionsdatei die Schemadatei, nicht die Sammlungsdatei.

Beispiel kann auf gefunden werden.

Wenn Sie immer noch Probleme haben, empfehle ich, ein Projekt auf Github zu erstellen, das Sie teilen können, wo Sie das Problem reproduzieren, ein Problem auf Meteor-Reagieren-Autoform-Projekt einreichen Ich werde eine Pull-Anforderung mit den Änderungen einreichen um dein Projekt zum Laufen zu bringen.