首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >.findQuery().get('length')每次给出0的结果

.findQuery().get('length')每次给出0的结果
EN

Stack Overflow用户
提问于 2013-08-11 08:37:00
回答 1查看 462关注 0票数 0

我使用.findQuery().get('length')来获取用于特定过滤的模型中可用记录的总数。

但是每次它显示结果为0。

我列出了我的代码这里

代码语言:javascript
复制
    total:function(){ 
        return App.Person.query({ contacttype: 1 }).get('length'); 
    }.property('@each.isLoaded')

我试过使用.find做同样的事情,但结果仍然是一样的:请检查这个链接

如何根据过滤标准计算记录长度?请检查这个链接在这里,我试图计算接触类型的长度。有人能告诉我怎么算吗?

现在,我已经把我最后的小提琴升级到了。如果我的模型记录在过滤的基础上发生变化,如何计算记录的总no。

请参考 (点击type1和type2过滤数据)。在这里,我无法根据过滤条件计算总记录。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-08-11 09:16:33

由于您已经在获取IndexRoute模型钩子中的记录,这将在控制器返回记录时设置控制器的content属性,因此您应该在控制器中访问控制器的content属性,并查看它的更改:

代码语言:javascript
复制
App.IndexController = Ember.ArrayController.extend({
  total: function() { 
    return this.get('content.length'); 
  }.property('content.length')
});

这里你的工作小提琴。

编辑

如果您想在控制器中筛选contacttype,就不应该在路由模型钩子中筛选,而是返回您拥有的所有记录:

代码语言:javascript
复制
...
model: function() {
  return App.Person.find();
}
...

然后在控制器中过滤:

代码语言:javascript
复制
App.IndexController = Ember.ArrayController.extend({
  total: function() { 
    return this.get('content.length'); 
  }.property('content.length'),

  totalContactType1: function() {
    return this.get('content').filterProperty('contacttype', 1).get('length');
  }.property('content.@each.contacttype'),

  totalContactType2: function() {
    return this.get('content').filterProperty('contacttype', 2).get('length');
  }.property('content.@each.contacttype')
});

再来一次小提琴

希望能帮上忙。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/18170175

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档