vendredi 19 octobre 2018

Ember this.store.findRecord will not update the existing model

I have a model which im using in a modal model is profile and its look like this.

model/profile.js

  id: DS.attr('string'),
  firstName: DS.attr('string'),
  lastName: DS.attr('string'),
  email: DS.attr('string'),
  job: DS.belongsTo('job'),

then im using the model in modal by passing through the parent route ( parent route is calling this.store.findRecord('profile', id );

sending the model to modal is works perfectly but when im trying to cancel from the modal i need to send api call again to fetch model data from api and re assign to the model by discarding all changes. i trying to do that in a function which is in the parent route ( child sending an action to parent to execute cancel) .

Action code in route of the parent

  cancelEdit( person ) {

      var profile = person.get( 'content' );

      console.log(  profile.get('id'));

      profile.set( 'uploadedAvatar', null );
      profile.set( 'file', null );


      var image = profile.get('cachedAvatar') ;
      var id = profile.get('id');

      console.log(person);


      this.store.findRecord( 'profile', id, {reload:true}).then( response => {
        console.log(response.get('job'))

        this.controllerFor( 'people/profile' ).set( 'person', response );


        profile.set( 'avatar', image );

        this.controllerFor( 'people/profile' ).set( 'animate', false );

        this.controllerFor( 'people/edit' ).set('isNewPosition',false);

        this.controllerFor( 'people/edit' ).set('imageCropper',false);
        this.controllerFor( 'people/edit' ).set('showImageCropper',false);
        this.controllerFor( 'people/edit' ).set('tmpImage',null);
        this.controllerFor( 'people/edit' ).set('tmpUploadedImage',null);
        this.controllerFor( 'people/edit' ).set('imageBlob',null);

        this.openModal( 'people/profile' );

      } )

    }

but the issue is it wont reset ( refresh or reassign the fresh data set )which is came through the api. the old changed data will be remain the same.

what did i miss here?




Aucun commentaire:

Enregistrer un commentaire