2016-07-30 87 views
0

我使用流星autoform和鐵路:路由器創建一個窗體,重定向到形式_id提交(即localhost3000 /提交/ _id。這一切都很好,但我現在想做的是使它所以我的模板只顯示形式的結果不是所有的人流星autoform顯示具體提交

這裏是我目前有

HTML代碼:

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

<template name="formDisplay"> 

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

</template> 

鉤:

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

路由:

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' 
}); 

形式:

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

回答

1

您需要添加一個ID過濾器到您的刊物,只返回您當前的特定文檔。

您的航線代碼:

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' 
}); 

您的出版物代碼:

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

謝謝你這麼多的作品完美! – Blezx