Mike.
Mike.

Reputation: 65

Trying to detect a change to a specific property in any of the records

Restating the problem:

Might be best to show how I got here: http://jsbin.com/qizog/114/edit?html,js,output

  1. I've binded the toRender property in the data with the checkbox.
  2. The checkbox belongs to the FilesController
  3. The SomethingController needs to respond to clicking the checkbox in order to complete its action
  4. I've set up a situation where FilesController can communicate with SomethingController using needs and an observer.
  5. I can send an action to FilesController to kick things off either when I use an action on the checkbox or when I use a click event in the View.
  6. But both of these block the binding of the toRender property and the checkbox. With either solution in place, I can check or uncheck the checkbox, but the data does not change (see Ember Inspector).

How can I both keep the binding and have the checkbox send an action to SomethingController?

Below was some attempt at seeing if I could observe the toRender data itself - outside of anything happening in the template. Maybe not the solution but I'm grasping at straws here.

I'd appreciate any help on this complicated problem. Thanks in advance!


Previous post:

I am trying to detect when there is a change to the number of App.File records that have the toRender attribute = true.

I wanted to set a controller property to a filter and then use observe. Is this just the wrong trail to go down? Does anyone have a better idea for doing this?

As a result of the following, am getting a "Uncaught TypeError: object is not a function" error. (ember-data.js:7325).

App.File = DS.Model.extend({
name: DS.attr('string'),
toRender: DS.attr('boolean'),
});


App.MyController = Ember.ArrayController.extend({
toRender: null,
init: function () {
    this.set('toRender', this.store.filter(App.File, {
        toRender: true
    }));
},
toRenderChanged: function () {
    console.log('toRender has changed!');
}.observes('toRender')
}

Upvotes: 1

Views: 649

Answers (1)

chopper
chopper

Reputation: 6709

Because this is an Ember.ArrayController you will need to use @each to observe changes on any of its objects. So you'd change

toRenderChanged: function () {
    console.log('toRender has changed!');
}.observes('toRender')

to

toRenderChanged: function () {
    console.log('toRender has changed!');
}.observes('@each.toRender')

No need for the filter

Upvotes: 0

Related Questions