mardi 10 décembre 2019

Ember network call payload behind one call

I am sending a network call using ember.js

The event is triggered by a check box click that adds or removes an item from an array called features.

Currently if I click on the checkbox to add "edit users" to the array, the features array is updated and the update method in my account_owner model is triggered.

The users object is passed in to the update method and when I log user.features the array has all three items including the one that was just added.

before sending to the network I create a payload object that looks like:

payload: { features: ["employee advocacy", "other", "edit_users"]}

Here is my update method

  update(user) {
      var payload = {
        features: user.features
      };
      console.log("@@@payload", payload)
      console.log("@@@this.accountID", this.accountID)
      const url = `/api/accounts/${this.id}/account_owners/${this.id}`;
      return put(url, payload).then(() => this);
    },

When this sends to the network only 2 of the three features are sent. the paylod looks like:

payload: { features: ["employee advocacy", "other"]}

The thing is if I click the edit users check box again, edit_users is removed from the features array as well as the payload in the method when I log it but when the call is sent to the network all three items including edit_users show up in the payload. like this:

payload: { features: ["employee advocacy", "other", "edit_users"]}

It seems like data in the network call is behind one click but I can not figure out why this is working this way.




Aucun commentaire:

Enregistrer un commentaire