0

我目前正在使用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"
        }    
    }
});
4

1 回答 1

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"
      }
    }
  }
});
于 2016-02-19T00:23:35.990 回答