如何为“插入”表单中的字段传递默认值?
我正在使用 Meteor 的软件包:Autoform、Collections2 和 Simple-Schema。
我的流程是:
- 用户在页面列表中选择某个值,然后
- 打开“插入”,我希望使用用户在上一步中选择的值来初始化该字段。
无法弄清楚如何使用 URL(或任何其他方式)传递参数。
问题是如何用值初始化表单。
假设我有一个网址:
http://localhost:3000/activity/new/Sport
===============
路由器.js:
...
Router.map(function () {
...
this.route('newActivity', {
path: '/activity/new/:tag',
data: function() {
Session.set('tag', this.params.tag);
return null;
}
});
...
===============
模型/activity.js
...
Activities = new Meteor.Collection("activities", {
schema: {
title: {
type: String,
label: 'название'
},
...
tag: {
type: String,
label: 'тэг'
}
}
});
===============
模板/avtibility.js
...
Template.newActivity.helpers({
defaultTag: function() {
return Session.get('tag');
}
});
...
===============
模板/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>
```