如何为“插入”表单中的字段传递默认值?
我正在使用 Meteor 的软件包:Autoform、Collections2 和 Simple-Schema。
我的流程是:
无法弄清楚如何通过 URL(或任何其他方式)传递参数。
问题是如何用值初始化表单。
假设我有一个 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: 'тэг'
}
}
});
================
模板/avtibity.js
...
Template.newActivity.helpers({
defaultTag: function() {
return Session.get('tag');
}
});
...
================
模板/事件.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
关于meteor - 如何以 'insert' 形式传递字段的默认值?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/24187784/