2016-07-29 8 views
0

私がしようとしているのは、meteor-autoformを使ってフォームを作成して、送信時に新しく生成されたルートにユーザをリダイレクトすることです。私の思考プロセスは、提出物_idを取ってiron:routerパラメーターに使用できるということです。私はこれまで持っていることは以下のようになります。meteor-autoformと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?

関連する問題