meteor - 使用 Iron Router 路由到 Meteor autoform 提交的新数据?

标签 meteor iron-router meteor-autoform

我正在使用带有 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);}
});

回调/ Hook
AutoForm.hooks({
  add: {
    onSuccess: function(doc) {
      Router.go('page', ???);
    }
  }
});

最佳答案

AutoForm Hook 将返回您的 docId。看:
https://github.com/aldeed/meteor-autoform#callbackshooks

this.docId: The _id attribute of the doc attached to the form, if there is one, or for an type='insert' form, the _id of the newly inserted doc, if one has been inserted.



所以使用:
Router.go('page',{_id: this.docId});

关于meteor - 使用 Iron Router 路由到 Meteor autoform 提交的新数据?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29903775/

相关文章:

android - 在 meteor 上安装 android-sdk - 已下载但在安装时出现错误

javascript - 如何展示这个集合?

Meteor 应用程序 - 尝试运行时卡在 "Starting your app"

javascript - meteor.js 铁路由器 : prevent static template re-render and glitching?

d3.js - Meteor,d3代码放在哪里?

javascript - 安装 iron :router in meteor app 后 Materialise 侧边栏导航停止工作

meteor - 在将其存储到数据库之前如何向快速表单添加额外的属性?

javascript - 如何在reactjs和meteor中显示加载器?

html - Bootstrap 内联无法按预期使用 meteor autoforms

javascript - 调用 Meteor.call() 并在 `before: insert` 钩子(Hook)内等待