【问题标题】:Meteor autoform access nested propertyMeteor autoform 访问嵌套属性
【发布时间】:2015-01-01 03:46:27
【问题描述】:

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

//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 name='units.1.qty'}} {{> afQuickField name='units.1.unitType'}}
  • 答案是为您继承的每个架构选项创建自定义子模板。稍后我会发布一个 fildde。

标签: meteor meteor-autoform


【解决方案1】:

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

试一试

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

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

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

让我知道这是否适合你!

一切顺利, 艾略特

【讨论】:

    猜你喜欢
    • 2016-02-13
    • 1970-01-01
    • 2015-11-24
    • 2012-10-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-06-21
    相关资源
    最近更新 更多