Ember.js 使用JSONAPI进行Ember数据侧加载
为我的路线生成的请求是Ember.js 使用JSONAPI进行Ember数据侧加载,ember.js,ember-data,json-api,Ember.js,Ember Data,Json Api,为我的路线生成的请求是http://api.myApp.com/tags/123/products,但我需要进行一些侧向加载以提高性能,所需的XHR为: http://api.myApp.com/tags/123/products?include=sideload1,侧载2,侧载3 我的路由器如下所示: this.route('tags', function() { this.route('tag', { path: ':id' }, function() { this.
http://api.myApp.com/tags/123/products
,但我需要进行一些侧向加载以提高性能,所需的XHR为:
http://api.myApp.com/tags/123/products?include=sideload1,侧载2,侧载3
我的路由器如下所示:
this.route('tags', function() {
this.route('tag', { path: ':id' }, function() {
this.route('products', function() {
});
});
});
我想为产品附带一些异步模型,目前我有:
// app/routes/tags/tag/products.js
model() {
return this.modelFor('tags.tag').get('products');
}
如何在route中添加查询参数?我在一个项目中做类似的事情,
store.query(键入,{query})代码>为我工作
定义模型并传入时,请尝试执行存储查询
{include: "sideload1,sideload2,sideload3"}
另一个选项是为您的模型创建适配器,并使用buildURL
添加查询参数。。。但是,这有点不规范,如果您的API遵循JSON API标准,则不需要这样做
App.TagsAdapter = DS.JSONAPIAdapter.extend({
buildURL: function(type, id) {
var baseURL = 'http://api.myApp.com/tags/123/products';
var method = '?include=sideload1,sideload2,sideload3';
return baseURL + method;
}
});