Emberjs数据限制集合 [英] Emberjs-data Limit collections

查看:76
本文介绍了Emberjs数据限制集合的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



http://jsbin.com/ubimes/1/



我试图找到限制模型的方法最后5个条目

  return Todos.Todo.find({limit:5}); 

但该查询不返回任何



任何想法如何限制收藏?

解决方案

您可以做的一种方法可能是限制您收集的内容, ,如下所示:

  App.IndexController = Ember.ArrayController.extend({
limitedContent:function(){
//在这种情况下'2'是限制参数
return this.get('content')。splice(0,2);
} .property('content')
});

.property('content')定义与控制器内容的绑定,并注意 #each 帮助器在内容更改时重新上传。



然后在您的模板中,循环 limitedContent 而不是内容

 < script type =text / x-handlebarsdata-template-name =index> 
{{#each color in limitedContent}}
{{color.name}}
{{/ each}}
< / script>

这里有一个工作 jsbin ,显示提到的概念。



希望它有助于


I have this jsbin, is a relly littl modification of the todos example

http://jsbin.com/ubimes/1/

I'm trying to find the way to limit a model to the last 5 entries

 return Todos.Todo.find({limit:5});

But that query returns nothing

Any idea how to limit collections ?

解决方案

A way you could do it could be limiting your collection's content in your respective controller holding the data, like this:

App.IndexController = Ember.ArrayController.extend({
  limitedContent: function() {
    // in this case '2' is the limit parameter
    return this.get('content').splice(0, 2);
  }.property('content')
});

The .property('content') defines a binding to the controller's content and takes care that the #each helper rerenders when the content changes.

And then in your template you loop over the limitedContent rather then the content:

<script type="text/x-handlebars" data-template-name="index">
  {{#each color in limitedContent}} 
    {{color.name}}
  {{/each}}
</script>

And here a working jsbin that show the concept mentioned.

Hope it helps

这篇关于Emberjs数据限制集合的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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