简体   繁体   中英

EmberJS: undefined is not function on helper when content changed

I got an error like these below when I trigger destroyRecord() on file app/controllers/transactions.js .

在此处输入图片说明

Below are my files.

app/templates/transactions.emblem

div
    format-datetime model.created_at
    bs-button clicked='destroyRecord' clickedParamBinding='model' size='xs' icon='glyphicon glyphicon-remove' type='danger' title='Delete'

app/helpers/format-datetime.js

import Ember from 'ember';

export function formatDatetime(input) {
  if ( input ) {
    return '%@/%@/%@'.fmt(input.getDate(), input.getMonth()+1, input.getFullYear());
  } else {
    return '';
  }
}

export default Ember.Handlebars.makeBoundHelper(formatDatetime);

app/controllers/transactions.js

....
actions: {
  destroyRecord: function() {
    if ( confirm('Are you sure to delete?') ) {
      this.get('model').destroyRecord();
      this.transitionToRoute('index');
    }
  }
....

But when I change file app/helpers/format-datetime.js to:

import Ember from 'ember';

export function formatDatetime(input) {
  if ( input ) {
    return input; // look this 
  } else {
    return '';
  }
}

export default Ember.Handlebars.makeBoundHelper(formatDatetime);

No error occured. So I guess my mistake is on my helper file. Any solution?

Either getDate , getMonth or getFullYear isn't defined on input, toss a debugger there and find out what input is.

export function formatDatetime(input) {
  if ( input ) {
    console.log(input);
    debugger;
    return '%@/%@/%@'.fmt(input.getDate(), input.getMonth()+1, input.getFullYear());
  } else {
    return '';
  }
}

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