1

The request generated for my route is http://api.myApp.com/tags/123/products, but I need to do some side loading to improve performance, the desired XHR would be:

http://api.myApp.com/tags/123/products?include=sideload1,sideload2,sideload3

My router looks like this:

  this.route('tags', function() {
    this.route('tag', { path: ':id' }, function() {
      this.route('products', function() {

      });
    });
  });

I'll like to sideload some async models for products, currently I have:

// app/routes/tags/tag/products.js

model() {
    return this.modelFor('tags.tag').get('products');
}

How would I go about adding query params in route?

4

1 回答 1

1

我在一个项目中做类似的事情并且store.query(type, { query });为我工作。http://emberjs.com/blog/2015/06/18/ember-data-1-13-released.html#toc_query-and-queryrecord

store.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;
    }
});
于 2015-07-21T20:32:19.337 回答