如何通过 Meteor 中的隐藏字段将 _id 传递给 autoForm?
How to pass _id to autoForm via hidden field in Meteor?
我有一个项目集和 Meteor.users 集。我的目标是将项目的文档_id 添加到用户名。
HTML:
<template name="insertName">
{{#each projectList}}
{{> projectView}}
{{/each}}
</template>
<template name="projectView">
{{#autoForm collection="Meteor.users" id="insertUser" type="insert"}}
{{> afQuickField name="username"}}
// From here I can access the _id property from the projects collection
// Question: How do I pass it to my form without creating an input field?
{{/autoForm}}
</template>
JS:
Meteor.users = new Meteor.Collection('projects');
Meteor.users.attachSchema(new SimpleSchema({
username: {
type: String,
max: 50
},
projectId: {
type: String,
max: 20
// Use autoValue to retrieve _id from projects collection?
}
});
使用上面的 HTML 代码,我知道我可以这样写:
{{> afQuickField name='projectId' value=this._id}}
然而,这会创建一个我不想要的输入字段。如何在没有可见输入字段的情况下将 _id 传递给我的 autoForm?或者也许有人可以指出我不同的方向?
我不确定这是最好的解决方案,但我认为这是解决您遇到的问题的一种方式:
{{> afQuickField name='projectId' value=this._id type='hidden'}}
有多种方法可以解决这个问题,但基本上,如果你想要一个隐藏字段,你必须将自动表单字段的类型设置为隐藏。
您可以执行以下任一操作:
{{> afQuickField name='projectId' value=this._id type='hidden'}}
或在架构本身上执行此操作
Meteor.users = new Meteor.Collection('projects');
Meteor.users.attachSchema(new SimpleSchema({
username: {
type: String,
max: 50
},
projectId: {
type: String,
max: 20,
autoform: {
type: 'hidden'
}
}
});
我有一个项目集和 Meteor.users 集。我的目标是将项目的文档_id 添加到用户名。
HTML:
<template name="insertName">
{{#each projectList}}
{{> projectView}}
{{/each}}
</template>
<template name="projectView">
{{#autoForm collection="Meteor.users" id="insertUser" type="insert"}}
{{> afQuickField name="username"}}
// From here I can access the _id property from the projects collection
// Question: How do I pass it to my form without creating an input field?
{{/autoForm}}
</template>
JS:
Meteor.users = new Meteor.Collection('projects');
Meteor.users.attachSchema(new SimpleSchema({
username: {
type: String,
max: 50
},
projectId: {
type: String,
max: 20
// Use autoValue to retrieve _id from projects collection?
}
});
使用上面的 HTML 代码,我知道我可以这样写:
{{> afQuickField name='projectId' value=this._id}}
然而,这会创建一个我不想要的输入字段。如何在没有可见输入字段的情况下将 _id 传递给我的 autoForm?或者也许有人可以指出我不同的方向?
我不确定这是最好的解决方案,但我认为这是解决您遇到的问题的一种方式:
{{> afQuickField name='projectId' value=this._id type='hidden'}}
有多种方法可以解决这个问题,但基本上,如果你想要一个隐藏字段,你必须将自动表单字段的类型设置为隐藏。
您可以执行以下任一操作:
{{> afQuickField name='projectId' value=this._id type='hidden'}}
或在架构本身上执行此操作
Meteor.users = new Meteor.Collection('projects');
Meteor.users.attachSchema(new SimpleSchema({
username: {
type: String,
max: 50
},
projectId: {
type: String,
max: 20,
autoform: {
type: 'hidden'
}
}
});