2016-07-30 16 views
0

meteor autoformとiron:routerを使用して、提出時に_idの形式にリダイレクトするフォームを作成します(つまり、localhost3000/submit/_id。 。Meteor autoformは特定の投稿を表示します

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

<template name="formDisplay"> 

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

</template> 

フック:

作るそれはので、私のテンプレートは、フォームだけの結果ではない、それらのすべてここに

は、私は現在

HTMLを持っているコードであることを表示します

ルーティング:

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

関連する問題