简体   繁体   中英

Ember.js computed property to return model ID array?

Updated: 11:36PST 07 Dec 2017

All I'm trying to do is create an array containing a list of current ID's in the model to use in a child component, but somehow seem to be missing something obvious. If it is relevant, I am using Ember 2.17.0 with Ember Data 2.17.0 as well.

The route returns an array of models very similar to a findAll , but modified to work with a REST endpoint I do not have any control over. I need an array of the id's from the model to use in a component embedded in the route. Based on feedback, I have attempted to implement this in both the route and the controller.

In the controller, I'm trying it this way.

searchIdArrayC: computed('model', () => {
  return this.get('model').map((record) => record.get('reachId'));
})

..and in the route I'm trying it this way.

searchIdArrayR: computed('model', () => {
  return this.modelFor('reaches').map((record) => record.get('reachId'));
});

When I look at it in the Chrome Ember Inspector, for both the route and controller it is telling me Error while computing: searchIdArrayR or Error while computing: searchIdArrayC .

Just to try and do some testing, I sent both the route and the controller to the console. With both the route and controller, the aforementioned methods are working, so I am really confused.

灰烬督察

Thank you in advance for any help or guidance you may be able to offer.

In route file, model is a function, but you are treating it like model property which is available in the corresponding controller.

If you can move searchIdArray computed property to corresponding controller then that should work.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM