gpt4 book ai didi

meteor 自动形成访问嵌套属性

转载 作者:行者123 更新时间:2023-12-02 04:52:22 26 4
gpt4 key购买 nike

我有一些链接模式,我正在尝试从主模式的表单访问子模式的属性。这是一口,我知道。代码可能有帮助:

//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"}} 但这也不太奏效。它没有只给我单元中包含的字段(即二级模式),而是遍历了主要和次要的所有字段。

想法?我不喜欢这种模式,但我想不出其他方法。

再次感谢大家。分贝

最佳答案

我自己也遇到过这个问题。

试一试

{{> afQuickField scope='units.unitType' name='units.unitType'}} 

如果您将修饰符转储到提交前 Hook 中,您应该能够看到子文档已成功填写

AutoForm.hooks({
someId: {
before: {
'insert': function(modifier) {
console.log(modifier);
}
}
}
});

让我知道这是否适合您!

祝一切顺利,埃利奥特

关于 meteor 自动形成访问嵌套属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26748937/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com