2016-07-30 7 views
0

Ich benutze Meteor AutoForm und Eisen: Router, um ein Formular zu erstellen, das auf das Formular _ID auf submit (dh localhost3000/submit/_ID. Umleiten, das alles funktioniert toll, aber was ich jetzt tun möchte ist machen es so nur meine Vorlage zeigt, dass Formen Ergebnisse nicht alle von ihnenMeteor Autoform eine spezifische Einreichung anzeigen

hier der Code ist derzeit ich habe

HTML:.

<div class="displayBox"> 
    {{#each Submits}} 
     {{> formDisplay}} 
    {{/each}} 
    </div> 

<template name="formDisplay"> 

    <h1> 
     {{title}} 
     {{subject}} 
     {{summary}} 
    </h1> 

</template> 

Hook:

AutoForm.addHooks('insertSubmit', { 
    onSuccess: function(doc) { 
    Router.go('formDisplay',{_id: this.docId}); 
    } 
}) 

Routing:

Router.route('/submit', { 
    layoutTemplate: 'submitLayout', 
    waitOn: function() { return Meteor.subscribe("Submits"); }, 
    loadingTemplate: 'loading' 
}); 

Router.route('/submit/:_id', { 
    name: 'formDisplay', 
    data: function() { return Products.findOne(this.params._id);}, 
    waitOn: function() { return Meteor.subscribe("Submits"); }, 
    loadingTemplate: 'loading' 
}); 

Form:

SubmitSchema = new SimpleSchema({ 
    title: { 
    type: String, 
    label: "Title" 
    }, 
    subject:{ 
    type: String, 
    label: "subject" 
    }, 
    summary:{ 
    type: String, 
    label: "Summary" 
    }, 
    author:{ 
    type: String, 
    label: "Author", 
    autoValue: function() { 
     return this.userId 
    }, 
    autoform: { 
    type: "hidden" 
    } 
}, 
    createdAt: { 
    type: Date, 
    label: "Created At", 
    autoValue: function(){ 
     return new Date() 
    }, 
    autoform: { 
     type: "hidden" 
    } 
    } 
}); 

Submits.attachSchema(SubmitSchema); 

Antwort

1

Sie benötigen einen ID-Filter in Ihrer Publikation hinzuzufügen, die nur Sie die aktuelle spezifische doc zurück.

Ihre Route Code:

Router.route('/submit/:_id', { 
    name: 'formDisplay', 
    data: function() { return Products.findOne(this.params._id);}, 
    waitOn: function() { return Meteor.subscribe("Submits", { '_id': this.params._id }); }, 
    loadingTemplate: 'loading' 
}); 

Ihre Veröffentlichung Code:

Meteor.publish('tasks', function(filter) { 
    filter = (filter ? filter : {}); 
    return Products.findOne(filter); 
}); 
+0

Vielen Dank funktioniert perfekt! – Blezx

Verwandte Themen