简体   繁体   中英

Ember.js - ember-pikaday not allowing preset date

I am trying to create a datepicker in ember.js using the ember-pikaday addon. 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. 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.

The problem with your case is due to the fact that you are passing a momentjs object to ember-pikaday directly. Instead of passing the momentjs object directly just create a computed property called as follows on your owner component:

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

and perform binding to 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. 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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