[英]Ember.js - Rendering additional data for a model
I have an app
model and apps have an id
and name
. 我有一个app
模型,并且应用程序具有id
和name
。
this.resource("apps", function() {
this.route('show', { path: ':app_id' });
});
I'd like to make the show
view show metrics about the app, but the query is pretty intense, so I don't want to include it in the call to the index
view (let's say this is a table). 我想让show
视图显示有关该应用程序的指标,但是查询非常激烈,因此我不想将其包含在对index
视图的调用中(假设这是一个表)。
I'm not sure if this is possible with ember-data because the app
would already be in the store with the simplified payload and not be re-requested for the show
view to get the metrics. 我不确定是否可以使用ember-data,因为该app
已经可以使用简化的有效负载存储在商店中,并且无需重新请求show
视图来获取指标。
Then my head went to making metrics a completely different model accessible from apps/1/metrics
and then making it another model and everything. 然后我的脑子去使指标成为可以从apps/1/metrics
访问的完全不同的模型,然后使其成为另一个模型和所有其他模型。
But if I sideload the data, i have to provide ID references to the metrics
for a particular app
. 但是,如果我加载数据,则必须为特定app
的metrics
提供ID引用。 And it's hasOne
so there's not really IDs as there would be for a database backed model. 而且它具有hasOne
因此没有真正的ID,就像数据库支持的模型那样。
What's the best way to load in additional data about a model or expand the information supplied in the show view? 加载有关模型的其他数据或扩展显示视图中提供的信息的最佳方法是什么?
The backend is Rails and this is an ember-cli project. 后端是Rails,这是一个ember-cli项目。
The easiest way is to retrieve the data in the Route
's afterModel
handler: 最简单的方法是在Route
的afterModel
处理程序中检索数据:
var ShowRoute = Ember.Route.extend({
model: function(params) {
// Load the model and return it.
// This will only fire if the model isn't passed.
},
afterModel: function(model, transition) {
// Load the rest of the data based on the model and return it.
// This fires every time the route re-loads (wether passed in or via model method).
}
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.