【问题标题】:How do I use the autoform update form with flowrouter in Meteor?如何在 Meteor 中使用带有 flowrouter 的 autoform 更新表单?
【发布时间】:2017-04-22 23:31:53
【问题描述】:

我在我的 Meteor 项目中使用 flowrouter,我正在尝试弄清楚如何将它与 autoform update 一起使用。换句话说,我正在尝试创建一个表单来更新我的实体。这意味着需要以某种方式将对象传递给模板,但我不确定如何根据autoform docs 你应该这样做;

<template name="updateBookForm">
  {{> quickForm collection="Books" doc=this id="updateBookForm" type="update"}}
</template> 

但是这个例子是关于铁路由器的。我需要哪些额外的代码才能使自动表单更新与流路由器一起使用?

更新...

我尝试了以下

Template.UpdateItem.helpers({
    item: function () {
        var theItem = Items.findOne({_id: FlowRouter.current().params.itemId});
        console.log("the item:"+JSON.stringify(theItem));
        return theItem
    }
});

在我的模板中

             {{#with item}}
                <div>
                    {{> autoForm collection="Items" id="updateItemForm"  doc=item class= "new-item-form" type="update"}}
                </div>
             {{/with}}

但我还是在发呆……

【问题讨论】:

    标签: forms meteor meteor-autoform flow-router


    【解决方案1】:

    它不知道“这个”是什么;它需要是您数据库中的一大块 JSON。通常,我像这样包装自动表单:

    {{#with getDocument}}
        {{> quickForm collection="Books" doc=this id="updateBookForm" type="update"}}
    {{/with}}
    

    ...并在JS中定义对应的helper:

    getDocument() {
        return Books.findOne({isbn: '978-3-16-148410-0'});
    }
    

    我正在使用流路由器,这不是特定于 Iron-router 的用例。

    【讨论】:

    • 啊,对,缺少 with ...。我认为 Iron 路由器在没有辅助功能的情况下开箱即用,谢谢
    • 尝试了这种方法,但我仍然一无所获......请参阅上面的编辑
    • 我会尝试的第一件事是“doc=this”而不是“doc=item”。尽管您在“膳食”上进行查找,但您拥有 collection="Items" 看起来也有些奇怪。可能没问题,但看起来很奇怪。
    • 所以看起来生成自动表单不起作用,但如果我添加快速表单字段它可以工作......不确定这是设计使然还是错误
    猜你喜欢
    • 2014-06-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-02-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-06-30
    相关资源
    最近更新 更多