vendredi 20 janvier 2017

model ready event not fired after transition to page where model is needed

10

I have a model with a bunch computed properties and things in a ready event:

  • one field of the model is a json field, for which I defined sub keys if non existent.
    • dynamic computed properties depending on the model content are defined

the model is associated to route rep/route/:idmodel with findRecord call to a backend

when I am on the page /rep/route/123, for instance, the ready event is fired and everything is ok,

so far so good

When I go elsewhere and return to /rep/route/123 the ready event is not fired again. it seems ok since there was not another ajax call, the record is in the data storage.

But what was defined in the ready callback seems not to persist. if the ready event was not called on the page /rep/route/123 I am returning on

  • subkeys of the json field are not there anymore
  • dynamic computed propertiesare not there

that is to say if the model has been loaded from the backend previously, the ready event was fired then, but the benefits of it (some computed properties defined dynamically on the model) disappear once I return on the page where it would be needed, if no new ajax call is needed.

the only workaround I found is to call model.reload on some didInsertElement of a component in the /rep/route template, to force ajax call and fire the ready event

I also tried to call this.get('model').ready() directly but it does not work.

So what would be the best way to keep all dynamic things defined in the ready event, when quitting the page and returning on it afterwards.

thanks




Aucun commentaire:

Enregistrer un commentaire