Meteor Error: Missing required parameters on path The missing params are: ["_id"]. The params object passed in was: {}

Meteor Error: Missing required parameters on path The missing params are: ["_id"]. The params object passed in was: {}

我的路线中有这个:

Router.map(function() {
...
    this.route('studentEdit', {
        path: '/student/:_id/edit',
        data: function() {
            return Students.findOne(this.params._id);
        },
    });

    this.route('studentDetail', {
        path: '/student/:_id',
        data: function() {
            return Students.findOne(this.params._id);
        }
    });

...

});

我在我的模板中使用了自动表单:

    {{#autoForm collection="Students" id="studentEdit" doc=this type="update"}}
        {{> afQuickField name='name'}} 
        {{> afQuickField name='phone'}} 
        {{> afQuickField name='address' rows=6}} 
        {{> afQuickField name='remarks' rows=6}}
    <button type="submit" class="btn waves-effect waves-light"><i class="material-icons">save</i></button>
    {{/autoForm}}

编辑页面加载正常,包含预填充的字段。当我保存时,它确实保存了,但是,它没有重定向到详细信息页面,并且 returns 控制台中出现此错误:

Exception in delivering result of invoking '/students/update': Error: Missing required parameters on path "/student/:_id". The missing params are: ["_id"]. The params object passed in was: {}.

更新 现在可以路由到详细信息页面,但错误仍然存​​在于控制台中。我肯定错过了什么。这是我为使其暂时正常工作所做的工作:

var moveOnRouter = {
    onSuccess: function(formType, result) {
        Router.go('studentDetail', {_id: this.docId});
    }
}

AutoForm.addHooks('studentEdit', moveOnRouter);

您需要明确 go 从您的表单提交到另一条路线。但是由于您的按钮是 submit 您还需要阻止默认的提交操作。

对于模板事件,您可以执行以下操作:

Template.myTemplate.events({
  'submit .btn'(ev) {
    ev.preventDefault();
    router.go('studentDetail',{ _id: this.docId });
  }
});

但是,由于您要挂钩自动表单,也许从按钮定义中删除 type="submit" 会更容易。