我使用.findQuery().get('length')来获取用于特定过滤的模型中可用记录的总数。
但是每次它显示结果为0。
我列出了我的代码这里。
total:function(){
return App.Person.query({ contacttype: 1 }).get('length');
}.property('@each.isLoaded')我试过使用.find做同样的事情,但结果仍然是一样的:请检查这个链接
如何根据过滤标准计算记录长度?请检查这个链接在这里,我试图计算接触类型的长度。有人能告诉我怎么算吗?
现在,我已经把我最后的小提琴升级到这了。如果我的模型记录在过滤的基础上发生变化,如何计算记录的总no。
请参考这 (点击type1和type2过滤数据)。在这里,我无法根据过滤条件计算总记录。
发布于 2013-08-11 09:16:33
由于您已经在获取IndexRoute模型钩子中的记录,这将在控制器返回记录时设置控制器的content属性,因此您应该在控制器中访问控制器的content属性,并查看它的更改:
App.IndexController = Ember.ArrayController.extend({
total: function() {
return this.get('content.length');
}.property('content.length')
});见这里你的工作小提琴。
编辑
如果您想在控制器中筛选contacttype,就不应该在路由模型钩子中筛选,而是返回您拥有的所有记录:
...
model: function() {
return App.Person.find();
}
...然后在控制器中过滤:
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')
});再来一次小提琴。
希望能帮上忙。
https://stackoverflow.com/questions/18170175
复制相似问题