Observing RecordArrays in EmberJS

46 views Asked by At

I have this setup right now:

App.Workspace = Em.Object.extend({
  users: null,
  usersChanged: Em.observer('users',function() {
    console.log('Users Updated!');
  }),
  ...
  initListeners: function() {
    var self = this;
    someObject.on('someEvent', function() {
      ...
      console.log('before set');
      self.set('users', self.store.all('users'));
    });
  }
});

I only get the output "before set", but not "Users updated!"

What am I missing?

1

There are 1 answers

0
artych On BEST ANSWER

1) Use

Em.observer('users.[]',function() {...});

to observe RecordArray. Look at jsbin demonstration for you. http://jsbin.com/noxijuloqi/edit?html,js,output

2) Make sure you've injected store into your Object properly, so self.store is not undefined.

3) Also you should correct typo

self.store.all('user');

instead

self.store.all('users');