【问题标题】:Meteor Error: Missing required parameters on path The missing params are: ["_id"]. The params object passed in was: {}Meteor 错误:路径上缺少必需的参数缺少的参数是:[“_id”]。传入的 params 对象是:{}
【发布时间】:2017-03-31 01:36:44
【问题描述】:

我的路线中有这个:

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:

    {{#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}}

编辑页面加载良好,带有预填充的字段。当我保存时,它确实保存了,但它不会重定向到详细信息页面,并在控制台中返回此错误:

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

【问题讨论】:

  • 你的router.go() 带你去哪里详细路线?
  • 在哪里添加 Router.go()?

标签: meteor iron-router


【解决方案1】:

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

使用模板事件,您可以执行以下操作:

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

但是由于您要挂钩 autoform,因此从按钮定义中删除 type="submit" 可能会更容易。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2022-01-01
    • 2021-01-24
    • 1970-01-01
    • 2023-02-07
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多