如何通过Meteor中的隐藏字段将_id传递给autoForm
How to pass _id to autoForm via hidden field in Meteor?
我有一个项目集合和Meteor.users集合。我的目标是将项目的document_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'}}
或者在模式本身上这样做
Meteor.users = new Meteor.Collection('projects');
Meteor.users.attachSchema(new SimpleSchema({
username: {
type: String,
max: 50
},
projectId: {
type: String,
max: 20,
autoform: {
type: 'hidden'
}
}
});
我不相信这是最好的解决方案,但我认为这是一种回避问题的方式:
{{> afQuickField name='projectId' value=this._id type='hidden'}}
相关文章:
- 如何将HTML id分配给元素,以及如何将JavaScript应用于元素
- difference between '$(<%= DDL.ID %>) & $('
- 使用Javascript获取所选选项ID
- 根据id将json数组组合为一个json数组
- 是否有一个JS/jQuery函数可以获取某个类的每个元素的ID
- 对id以某个字符串开头的元素进行计数
- 如果元素's的ID以数字开头
- 通过id和class属性获取元素
- 根据选项卡内部的文本链接中的哈希ID动态选择jqueryUI选项卡
- 使用当前日期生成随机id
- Javascript-ID冲突的几率
- Href:当前DIV中的目标ID
- 无法获取属性'Id'使用Knockout.js的未定义或空引用API
- Javascript复选框函数:;缺少:在属性id之后"
- Twitter引导程序Typeahead-Id&标签
- 如何与特定ID交谈
- chart.series[id].remove()无法刷新高位图表/高位股票中其他系列的图例属性
- 如何在速度模板中获取LiferayPortlet实例id
- 谷歌地图可以't添加正确的标记ID
- Meteor AutoForm:带id的表单;asdf”;需要“;模式“;或“;集合“;属性