2016-07-29 206 views
0

我想要做的是創建一個流星autoform的形式,將用戶重定向到提交新生成的路線。我的思考過程是,我可以提交_id並將其用於iron:router參數。因爲跟着我至今看起來:使用流星自動生成和鐵的動態路由問題:路由器

形式

Submits = new Meteor.Collection('Submits'); 

Submits.allow({ 
    insert: function(username, doc){ 
    return !!username; 
    } 
}); 

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

路由

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

Router.route('/submit/:_id', { 
    name: 'formDisplay', 
    data: function() { 
    return Submits.findOne({this.params._id}); 
    } 
}); 

的創作然後我只是平均發佈和查找調用。我的問題是我不知道如何執行提交重定向,我不知道如何顯示新生成的路線上的表單結果。

任何幫助,將不勝感激。

回答

0

我能夠通過添加一個autoform.hook並改變我的路由一點。

自動窗體鉤:

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

路由:

Router.route('/submit/:_id', { 
    name: 'submitLayout', 
    data: function() { return Products.findOne(this.params._id);} 
}); 

我得到了這個職位這一信息:

Route to the new data submitted by Meteor autoform using iron router?