简体   繁体   English

Ember.js - ember-pikaday不允许预设日期

[英]Ember.js - ember-pikaday not allowing preset date

I am trying to create a datepicker in ember.js using the ember-pikaday addon. 我正在尝试使用ember-pikaday插件在ember.js中创建一个日期选择器。 The datepicker should have a date in it when it is displayed. 日期选择器在显示时应该有一个日期。 So, I added the following code to my template: 所以,我在我的模板中添加了以下代码:

{{pikaday-input value=rental.date format="MMMM Do YYYY" yearRange="2016" useUtc=true}}

However, even though I specify the value as rental.date , the input is blank. 但是,即使我将值指定为rental.date ,输入也是空白的。 I know that the value of rental.date is not null because when I set the placeholder to rental.date , the placeholder's date is correct. 我知道rental.date的值不为null,因为当我将占位符设置为rental.date ,占位符的日期是正确的。

The problem with your case is due to the fact that you are passing a momentjs object to ember-pikaday directly. 您的案例的问题是由于您将momentjs对象直接传递给ember-pikaday。 Instead of passing the momentjs object directly just create a computed property called as follows on your owner component: 而不是直接传递momentjs对象,只需在您的所有者组件上创建一个如下所示的计算属性:

  rentalDate:Ember.computed('rental.date', function() {
      return this.get('rental.date').toDate();
  }),

and perform binding to rentalDate. 并执行绑定到rentalDate。 ember-pikaday does not handle momentjs object passed in by itself, just extract the actual javascript date object via toDate() as shown in code snippet above. ember-pikaday不处理自己传入的momentjs对象,只需通过toDate()提取实际的javascript日期对象,如上面的代码片段所示。 Just for clarification you can also pass formatted string to ember-pikaday such as "25/05/2016", "2016.05.25", etc. It will also handle such string values properly. 只是为了澄清你也可以将格式化的字符串传递给ember-pikaday,例如“25/05/2016”,“2016.05.25”等。它还将正确处理这些字符串值。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM