8

AutoForm & Iron Router で Meteor を使用しています。

データを挿入するためのオートフォームがあり、挿入が成功した後に追加したデータのページにリダイレクトしたいと考えています。どうすればいいですか?

対象は次のとおりです。

{{#autoForm collection="Products" id="add" type="insert"}}
    <h4 class="ui dividing header">Products Information</h4>
      {{> afQuickField name='name'}}
      {{> afQuickField name='info'}}
    <button type="submit" class="ui button">Insert</button>
{{/autoForm}}

アイアンルーター:

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

コールバック/フック

AutoForm.hooks({
  add: {
    onSuccess: function(doc) {
      Router.go('page', ???);
    }
  }
});
4

3 に答える 3

6

AutoForm フックは docId を返します。参照: https://github.com/aldeed/meteor-autoform#callbackshooks

this.docId: フォームに添付されたドキュメントの _id 属性 (存在する場合)、または type='insert' フォームの場合、新しく挿入されたドキュメントの _id (挿入されている場合)。

だから使用:

Router.go('page',{_id: this.docId});
于 2015-04-27T19:46:37.243 に答える