有没有办法在模式中指定选项助手?我试过:
架构
{
favoriteColor: {
type: String,
autoform: {
options: "colorOptions"
}
}
}
但这似乎不起作用。
以下技术适用于在表单中显示带有选项的选择:
架构
{
favoriteColor: {
type: String
}
}
helper
Template.myFormTemplate.helpers({
colorOptions: function () {
return Colors.find().map(function (c) {
return {label: c.name, value: c._id};
});
}
});
模板
{{> afQuickField name="favoriteColor" options=colorOptions}}
在我的实际模式中,我有一个对象数组,并且在每个对象中我需要从不同的集合中选择一个项目。当您使用 afArrayField 时,您不能再像我在上面的模板中那样设置模板中的选项(因为它是一个对象数组,并且对象中的一个元素将引用助手)。
当我定义方案时,我唯一的选择是查询数据库吗?我想这会让它变得无 react ,对吧?
最佳答案
{
favoriteColor: {
type: String,
autoform: {
options: function () {
return Colors.find().map(function (c) {
return {label: c.name, value: c._id};
});
}
}
}
}
将辅助函数直接插入模式中将起作用。我正在做类似的事情,它是被动的。
关于meteor - 自动生成 : can I specify the options helper in the schema?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28297397/