简体   繁体   English

Ember.js计算属性以返回模型ID数组?

[英]Ember.js computed property to return model ID array?

Updated: 11:36PST 07 Dec 2017 更新时间:2017年12月7日11:36PST

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. 我要做的就是在模型中创建一个包含当前ID列表的数组,以供子组件使用,但似乎以某种方式缺少明显的东西。 If it is relevant, I am using Ember 2.17.0 with Ember Data 2.17.0 as well. 如果相关,我还将Ember 2.17.0和Ember Data 2.17.0一起使用。

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. 该路由返回的模型数组与findAll非常相似,但是修改后可以与REST端点一起使用,而我对此没有任何控制权。 I need an array of the id's from the model to use in a component embedded in the route. 我需要模型中的ID数组,以便在路由中嵌入的组件中使用。 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 . 当我在Chrome Ember Inspector中查看路由和控制器时,它都在告诉我Error while computing: searchIdArrayRError 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. 在路由文件中, model是一个函数,但是您将其视为model属性,该属性在相应的控制器中可用。

If you can move searchIdArray computed property to corresponding controller then that should work. 如果您可以将searchIdArray计算的属性移动到相应的控制器,则应该可以使用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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