【问题标题】:Autoform: can I specify the options helper in the schema?Autoform:我可以在模式中指定选项助手吗?
【发布时间】:2023-03-18 15:13:01
【问题描述】:

有没有办法在模式中指定选项助手?我试过了:

架构

{
  favoriteColor: {
    type: String,
    autoform: {
      options: "colorOptions"
    }
  }
}

但它似乎不起作用。

以下技术可以很好地在表单中显示带有选项的选择:

架构

{
  favoriteColor: {
    type: String
  }
}

助手

Template.myFormTemplate.helpers({
  colorOptions: function () {
    return Colors.find().map(function (c) {
      return {label: c.name, value: c._id};
    });
  }
});

模板

{{> afQuickField name="favoriteColor" options=colorOptions}}

在我的实际架构中,我有一个对象数组,并且在每个对象中我需要从不同的集合中选择一个项目。当您使用 afArrayField 时,您不能再像我在上面的模板中那样在模板中设置选项(因为它是一个对象数组,并且对象中的一个元素将引用帮助器)。

当我定义方案时,我唯一的选择是查询数据库吗?我猜这会让它变得无反应,对吧?

【问题讨论】:

    标签: meteor meteor-autoform


    【解决方案1】:
    {
      favoriteColor: {
        type: String,
        autoform: {
          options: function () {
        return Colors.find().map(function (c) {
          return {label: c.name, value: c._id};
        });
      }
        }
      }
    }
    

    将辅助函数直接插入架构中会起作用。我正在做类似的事情,它是被动的。

    【讨论】:

    • 我也在使用这个功能,但是我的选项没有出现。在我的架构显示我期望从数据库中获得的值之后,在控制台中记录相同的函数。想法?
    • @RandyHall 确保您订阅了您为选项提取的数据。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-11-10
    • 1970-01-01
    • 1970-01-01
    • 2015-01-26
    • 2012-06-18
    • 2014-10-27
    相关资源
    最近更新 更多