jeudi 22 novembre 2018

Even after refresh some attributes in the model are not changed

I am new to EmberJS, and facing problem with model data updation

Controller :

export default Ember.Controller.extend({
queryParams: ['jobid'],
jobid: null,
currentCount: null,

actions: {
 onOffToggle(e) {
  var isChanged = this.get('model.b.isChanged');
  this.set('model.b.enable', e.target.checked);
  this.set('model.b.isChanged', !isChanged);
  console.log(this.get('model.b.isChanged'))
},
iterationCountChange() {
  var currentCount = this.get('currentCount');
  var isCountChanged =
      (currentCount != this.get('model.b.count')) ? true : false;
  this.set('model.b.isCountChanged', isCountChanged);
}
}});

Route:

export default Ember.Route.extend({
ajax: Ember.inject.service(),

beforeModel: function (transition) {
this.jobid = transition.queryParams.jobid;
},
model(){
  return Ember.RSVP.hash({
    a:   this.store.queryRecord('a', {jobid: this.get("jobid")}),
    b: this.store.queryRecord('b', {id: this.get("jobid")})
 });
},
setupController: function(controller, model) {
  this._super(controller, model)
controller.set('currentCount', model.tunein.get('iterationCount'))
},

actions: {
 paramChange(a, b)
  Ember.$.ajax({
    url: "/rest/test",
    type: 'POST',
    contentType: 'application/json',
    data: JSON.stringify({
       b: b,
       a: a
     })
   }).then(response => {
    this.refresh();
  })
},
error(error, transition) {
  if (error.errors[0].status == 404) {
    return this.transitionTo('not-found', { queryParams: {'previous': window.location.href}});
   }
  }
 }
});

Here in controller I am keeping track if some value have changed, and if they have changed then update the flag related to their change, these flags like isChanged and isCountChanged are the part of the model's data, after user cliks submit button , paramChange action is called and then a post call is made to update the db for respective property changes, and then this.refresh() is called to render the latest model data.

But the problem is, once isChanged and/or isCountChanged are changed from their default value, then they don't reset to the new value present in the model data, e.g. after refresh the value to both these flags should be reset to false but it comes always true, I checked the value in the setUpController hook for the values of these flags and it confirms to true.

According to me it has something to with the controller, since any value which is used in controller once is not resetting to new value coming after refresh.

Kindly help I am spent a lot of time in this and got nothing till now, do inform if any extra information is required.




Aucun commentaire:

Enregistrer un commentaire