【问题标题】:Meteor datepicker month and year only仅流星日期选择器月份和年份
【发布时间】:2016-02-19 11:52:45
【问题描述】:

我目前正在使用aldeed:autoform-bs-datepickerrajit:bootstrap3-datepicker。我想将日期范围限制为年和月。我已经在助手中尝试过,但它不起作用。有什么想法吗?

Template.user.helpers({
    datePicker: function() {
            $("#datepicker").datepicker( {
            format: "mm/yyyy",
            startView: "months", 
            minViewMode: "months"
        });
    }
});

路径:Schema.js

Schema.Date = new SimpleSchema({
    startDate: {
        type: Date,  
        optional: true,
        autoform: {
            type: "bootstrap-datepicker",
            "data-date-autoclose": "true"
        }    
    }
});

【问题讨论】:

  • 感谢您的建议。我累了,但它没有用。您需要更多信息吗?

标签: meteor meteor-autoform simple-schema


【解决方案1】:

试试这个:

Template.user.onRendered(function() {
  $("#datepicker").datepicker( {
    format: "mm/yyyy",
    startView: "months",
    minViewMode: "months"
  });
});

您应该在渲染模板时初始化datepicker,而不是在助手上。希望能帮助到你。另外,确保日期选择器有id="datepicker"

如果仍然不起作用,请按如下方式修改您的架构并删除$("#datepicker")

Schema.Date = new SimpleSchema({
  startDate: {
    type: Date,
    optional: true,
    autoform: {
      type: "bootstrap-datepicker",
      datePickerOptions: {
        format: "mm/yyyy",
        startView: "months",
        minViewMode: "months"
      }
    }
  }
});

【讨论】:

  • 这似乎也不起作用。我附上了架构(见上文)。 #datepicker 应该是 #startDate 还是其他?
  • 知道了。让我为你创建一个 Meteorpad,我会根据建议编辑我的答案。
  • 似乎 Meteorpad.com 已关闭。让我知道在架构上设置选项是否适合您。
  • 太棒了!如果我删除 template.user.Onrendered 并只使用您的架构解决方案,它会很有效。谢谢@lucatros!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多