2016-07-14 15 views
0

私はこれを2,3週間苦労しています。 私のウェブページにmeteor-react-autoformを使用します。 私はThe Meteor ChefのBaseを使用しています。 助けを借りて本当にありがとうございます流星反応オートフォームに何も表示されていません

悪い英語を残して申し訳ありませんが、ここにファイルがあります。

:これは、定義されたメソッドを持つファイルです。ここ
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); 

フォームで、挿入ハンドラ

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" 
    /> 
); 

この

は私が私のスキーマとコレクションを定義するファイルであります
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); 
    } 
}); 

答えて

0

コレクションとスキーマを別々のファイルで定義する必要があります。スキーマを新しいファイルに移動し、スキーマをコレクションファイルにインポートしてSimeplSchemaに転送し、コレクションとして保存します。次に、反応ファイルで、コレクションファイルではなくスキーマファイルをインポートします。

例は、にあります。

まだ問題が残っている場合は、問題を再現しているところで共有することができるGithubのプロジェクトを作成し、meteor-react-autoformプロジェクトの問題を提出することをお勧めします。あなたのプロジェクトを成功させる。

関連する問題