dimanche 5 février 2017

EmberJS - Custom Transform type error

I have a date string passed in from my backend that looks something like:

1903-01-07T00:35:15

My transform.js file called dst-date looks like

import DS from 'ember-data';

export default DS.Transform.extend({
  deserialize(serialized) {
    console.log(serialized);
    const month = {
      1: "Jan",
      2: "Feb",
      3: "Mar",
      4: "Apr",
      5: "May",
      6: "Jun",
      7: "Jul",
      8: "Aug",
      9: "Sept",
      10: "Oct",
      11: "Nov",
      12: "Dec"
    };
    let dstDate = serialized.split(/-|T/);
    let ansStr = `${dstDate[2]} ${month[Number(dstDate[1])]} ${dstDate[0]} ${dstDate[3]} GMT`;
    return ansStr;
  },

  serialize(deserialized) {

    return deserialized;
  }
});

I have two tabs that compare change sets and on the current change set it renders fine. For example: Image 1

But when I click on the previous change set to compare I get this error:

ember.debug.js:19750 TypeError: Cannot read property 'split' of null
    at Class.deserialize (transform.js:19)
    at json.js:179
    at attr.js:181
    at cb (ember.debug.js:21522)
    at OrderedSet.forEach (ember.debug.js:21324)
    at Map.forEach (ember.debug.js:21526)
    at Function.eachTransformedAttribute (attr.js:180)
    at Class.applyTransforms (json.js:172)
    at Class.normalize (json.js:523)
    at Class.normalize (rest.js:150)

Where on line 19, it is dstDate=serialized.split(/-|T/);

Why doesn't this work?




Aucun commentaire:

Enregistrer un commentaire