如何以"插入"形式传递字段的默认值?

Ale*_*zin 4 meteor meteor-autoform meteor-collection2 simple-schema

如何以"插入"形式传递字段的默认值?

我正在使用Meteor的软件包:Autoform,Collections2和Simple-Schema.

我的过程是:

  1. 用户在页面上的列表中选择一些值,然后
  2. 打开"插入",我希望使用用户在上一步中选择的值初始化一个字段.

无法弄清楚如何使用URL(或任何其他方式)传递参数.问题是如何使用值初始化表单.

假设我有一个URL:

http://localhost:3000/activity/new/Sport
Run Code Online (Sandbox Code Playgroud)

=============== router.js:

...
Router.map(function () {
    ...
    this.route('newActivity', {
        path: '/activity/new/:tag',
        data: function() {
            Session.set('tag', this.params.tag);
            return null;
        }
    });
    ...
Run Code Online (Sandbox Code Playgroud)

=============== models/activity.js

...
Activities = new Meteor.Collection("activities", {
    schema: {
        title: {
            type: String,
            label: '????????'
        },
        ...
        tag: {
            type: String,
            label: '???'
        }
    }
});
Run Code Online (Sandbox Code Playgroud)

================ templates/avtibity.js

...
Template.newActivity.helpers({
    defaultTag: function() {
        return Session.get('tag');
    }
});
...
Run Code Online (Sandbox Code Playgroud)

================ templates/activity.html

...
<template name="newActivity">
    <h1>Create new Activity!</h1>
    {{#autoForm collection="Activities" id="insertActivityForm" type="insert"}}
        {{> afQuickField name="title"}}
        ...
        {{> afQuickField name="tag" value="   ??????    "}} // ? {{defaultTag}}
        ho ho ho {{defaultTag}}
    {{/autoForm}}
</template>
Run Code Online (Sandbox Code Playgroud)

```

Ale*_*zin 8

感谢Eric Dobbertin:

  1. 您可以将值设置为等于返回所需值的帮助器({{> afQuickField name ="tag"value = valueHelper}})
  2. 列表项您可以将doc设置为一个值设置为您想要的对象.就像你想要更新表格一样.

https://github.com/aldeed/meteor-autoform/issues/210