Quantcast
Viewing all articles
Browse latest Browse all 4829

Object saved into Service lost an attribute value

@belgoros wrote:

I have a service current-shop.js which is defined s follows:

#services/current-shop.js

import Service from '@ember/service';

export default Service.extend({
  shop: null,

  setShop(shop) {
    this.set('shop', shop)
  }
});

The main purpose of this service is to always keep traces of the current shop (that could be changed by selecting another one from a drop-down list).

I set its shop value ony in two cases:

  • in the very beginning when logging the user:
this.get('currentShop').setShop(user.get('shop'));
  • when a user selects another shop from the drop-down list:
# components/shop-list.js

export default Component.extend({
  i18n: service(),
  currentShop: service(),
  shops: [],
  tagName: '',
  aShop: null,
  notFoundMessage: t('components.shop.list.messages.not.found'),

  actions: {
    chooseShop(shop) {
      this.set('aShop', shop);
      this.get('currentShop').setShop(shop);
    }
  }
});

The shop-list.hbs component looks like that:

# templates/components/shop-list.hbs

<label for="shop_select">{{t 'components.shop.list.labels.change.shop'}}</label>

{{#power-select
  selected=aShop
  options=shops
  searchField="name"
  noMatchesMessage=notFoundMessage
  onchange=(action "chooseShop")
  as |shop|
}}
  {{shop.shopName}}
{{/power-select}}

The problem I have is that I can display all the needed values coming from the current shop but the only one: modifiedBy.

I pass modified_by value from the backend to Ember. I have Shop model defined as follows in Ember:

# models/shop.js
export default DS.Model.extend({
..
  modifiedBy:    DS.attr('string'),
... //other attributes come here
  shopName: computed('identifier', 'name', function() {
    return `${this.get('identifier')}-${this.get('name')}`;
  })
});

The question how is it possible to have one attribute (or property) of an objet attached to a service disappeared ? Is there any way to trace it ? Thank you.

Posts: 2

Participants: 1

Read full topic


Viewing all articles
Browse latest Browse all 4829

Trending Articles