如何在Meteor中使用自动更新表单和flowrouter?

时间:2016-12-07 21:05:28

标签: forms meteor meteor-autoform flow-router

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

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

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

更新...

我尝试了以下

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

但我仍然没有得到什么......

1 个答案:

答案 0 :(得分:1)

它不知道&#34;这个&#34;是;它需要是你的数据库中的一大块JSON。通常,我会像这样包装自动形式:

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

...并在JS中定义一个相应的帮助器:

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

我使用的是流量路由器,这不是铁路由器特定用例。