samedi 19 août 2017

ember computed not being updated

i have a computed property in ember

  isCurrentUserLikeIt: Ember.computed('likestatuses.@each.user_id', function () {
    const userId = parseInt(this.commonService.getId());
    const likestatuses = this.get('likestatuses');

    return likestatuses.filterBy('user_id', userId).get('length') !== 0;
  })

the computed property must be updated when user invoke an action.

this.doSave("likestatus", likestatus).then(function (result) {
        if (result.userlike) {
          const likestatuses = context.get('likestatuses');
          likestatuses.push(likestatusItem);
          context.set('likestatuses', likestatuses);
        } else {
          const likestatuses = context.get('likestatuses').filter(function (item) {
            return item.user_id !== userId
          });
          context.set('likestatuses', likestatuses);
        }

        context.debug(context.get('likestatuses'));
      });

the isCurrentUserLikeIt property is updated when the statement in this.doSave, is in else. but when the statement is in if (result.userlike) the isCurrentUserLikeIt property did not change :(

can anyone solve this




Aucun commentaire:

Enregistrer un commentaire