过滤器分页传递参数到异步ember数据关系请求 [英] filter paginate pass parameters to asynchronous ember data relationship requests

查看:142
本文介绍了过滤器分页传递参数到异步ember数据关系请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



这是我的作者模型:

我想要实现对异常数据的分页/过滤。 / p>

 导出默认DS.Model.extend({
用户:DS.belongsTo('user'),
文章:DS.hasMany('article',{async:true}),
名称:DS.attr('string'),
电子邮件:DS.attr('string')
});

路线:

 code> export default Ember.Route.extend({
model:function(params){
return this.store.find('author',params.author_id);
}
});

控制器:

 code> export default Ember.ObjectController.extend({
popularArticles:function(){
return this.get('model.articles')。filter({tab:'popular'}) ;
} .property('model.articles')
});

请注意,模型有一个文章属性 DS.hasMany('article',{async:true})关系。



如果我使用此属性请求是 authors / 1 / articles 及其异步的。



这是很好,直到我需要提出请求 author / 1 / articles?page = 2 authors / 1 / articles?tab =hot p>

一个可能的方法是,如控制器所示,我有一个 popularArticles 属性过滤 model.articles 属性,并将过滤请求,而不加载所有文章。



如何将查询参数传递给异步加载的关系在ember数据?

解决方案

此插件可能有帮助: https://github.com/mdehoog/ember-data-has-many-query



允许您将查询参数添加到 has-many 关系,例如:



post.query('comments',{page:1});


I want to implement paging/filtering on ember data asynchronously.

This is my author model:

export default DS.Model.extend({
  user: DS.belongsTo('user'),
  articles: DS.hasMany('article', { async: true }),
  name: DS.attr('string'),
  email: DS.attr('string')
});

route:

export default Ember.Route.extend({
  model: function(params) {
    return this.store.find('author', params.author_id);
  }
});

controller:

export default Ember.ObjectController.extend({
  popularArticles: function() {
    return this.get('model.articles').filter({ tab: 'popular' });
  }.property('model.articles')
});

Note that model has an articles property with DS.hasMany('article', { async: true}) relationship.

If I use this property this request is made authors/1/articles and its asynchronous.

This is fine until I need to make request like authors/1/articles?page=2 or authors/1/articles?tab="hot".

One possible approach is, as shown in the controller, I have a popularArticles property that filters the model.articles property, and will make the filtered request without loading all the articles.

How can I pass query parameters to asynchronously loaded relationships in ember data?

解决方案

This addon may help: https://github.com/mdehoog/ember-data-has-many-query.

Allows you to add query params to has-many relationships, eg:

post.query('comments', { page: 1 });

这篇关于过滤器分页传递参数到异步ember数据关系请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆