Meteor自动表单访问嵌套属性
我有一些链接的模式,并且正在尝试从主模式的表单访问子模式的属性。这是一口,我知道。代码可能有助于:Meteor自动表单访问嵌套属性,meteor,meteor-autoform,Meteor,Meteor Autoform,我有一些链接的模式,并且正在尝试从主模式的表单访问子模式的属性。这是一口,我知道。代码可能有助于: //js Collection = new Meteor.Collection('collection'); Schemas = {}; Schemas.secondary = new SimpleSchema({ unitType: { type: String, autoform: { type: 'select', optio
//js
Collection = new Meteor.Collection('collection');
Schemas = {};
Schemas.secondary = new SimpleSchema({
unitType: {
type: String,
autoform: {
type: 'select',
options: //function with all the options
}
}
});
Schemas.primary= new SimpleSchema({
name: {
type: String,
},
units: {
type: [ Schemas.secondary ]
}
});
Collection.attachSchema(Schemas.primary);
//HTML
{{#autoForm collection="Collection" id="someId" type="insert"}}
{{> afQuickField name='name'}} // this works
{{> afQuickField name='units'}} // this works
{{> afQuickField name='units.unitType'}} // this doesn't work :-(
{{/autoForm}}
我这样做的原因是,我希望根据选择框的值有条件地显示辅助架构中的其他属性。我还尝试在表单中放入一个表单,然后运行{{each afFieldNames name='units}},但这也不太管用。它不只是给我单元中包含的字段,即辅助模式,而是循环遍历主模式和辅助模式的所有字段
想法?我不喜欢这种模式,但我想不出另一种方式
再次感谢大家。
db我自己也有这个问题 试一试
{{> afQuickField scope='units.unitType' name='units.unitType'}}
如果在提交前挂钩中转储修改器,则应该能够看到子文档已成功填写
AutoForm.hooks({
someId: {
before: {
'insert': function(modifier) {
console.log(modifier);
}
}
}
});
让我知道这是否适合你
祝你一切顺利,
Elliott尝试{{>afQuickField name='units.1.qty'}{{{>afQuickField name='units.1.unitType'}}答案是为您从中继承的每个架构选项创建自定义子模板。我一会儿就发一封邮件。