【问题标题】:Meteor AutoForm simpleSchema this.field function does not workMeteor AutoForm simpleSchema this.field 功能不起作用
【发布时间】:2016-06-19 05:59:31
【问题描述】:

我在 Meteor 中使用 SimpleSchema 时遇到了麻烦。

我的目标是根据“type”字段值更改“min”字段,所以我编写了这段代码。

'min': {
    type: Number,
    optional: true,
    label: function() {
      if(this.field('type').value == "Year") {
        return "Minimum Year"
      }
      return "Minimum Value"
    }
  },

但是当我调试它时,它显示这是一个空白对象。

我真的不知道如何处理这个问题。

请帮帮我!

【问题讨论】:

  • label 选项没有this.field(),尝试使用custom
  • 那么标签怎么处理呢?我正在使用 autoform 快速字段,如下所示。 {{> afQuickField name="min"}}
  • 您可以创建助手并附加到afQuickField中的标签字段
  • 你能教教我吗?

标签: meteor meteor-autoform


【解决方案1】:

希望这有帮助,

{{> afQuickField name="min" label=checking}}

Template.x.helpers({
  checking:function(){
    if(Autoform.getFieldValue(field,formId)=="expected") 
      return "expected label"
    else
      return ""
  } 
})

【讨论】:

  • 我认为将助手应用于所有使用模式的模板是不可靠的。那么如果我使用 Template.RegisterHelper 而不是 Template.x.helpers 呢?
猜你喜欢
  • 1970-01-01
  • 2016-01-08
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-12-18
  • 2020-09-26
  • 2017-10-22
  • 2016-04-30
相关资源
最近更新 更多