Ale*_*zin 4 meteor meteor-autoform meteor-collection2 simple-schema
如何以"插入"形式传递字段的默认值?
我正在使用Meteor的软件包:Autoform,Collections2和Simple-Schema.
我的过程是:
无法弄清楚如何使用URL(或任何其他方式)传递参数.问题是如何使用值初始化表单.
假设我有一个URL:
http://localhost:3000/activity/new/Sport
=============== router.js:
...
Router.map(function () {
    ...
    this.route('newActivity', {
        path: '/activity/new/:tag',
        data: function() {
            Session.set('tag', this.params.tag);
            return null;
        }
    });
    ...
=============== models/activity.js
...
Activities = new Meteor.Collection("activities", {
    schema: {
        title: {
            type: String,
            label: '????????'
        },
        ...
        tag: {
            type: String,
            label: '???'
        }
    }
});
================ templates/avtibity.js
...
Template.newActivity.helpers({
    defaultTag: function() {
        return Session.get('tag');
    }
});
...
================ 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>
```
感谢Eric Dobbertin:
https://github.com/aldeed/meteor-autoform/issues/210
| 归档时间: | 
 | 
| 查看次数: | 3767 次 | 
| 最近记录: |