Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/django/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ember.js .findQuery().get(';length';)每次将结果作为0_Ember.js_Ember Data - Fatal编程技术网

Ember.js .findQuery().get(';length';)每次将结果作为0

Ember.js .findQuery().get(';length';)每次将结果作为0,ember.js,ember-data,Ember.js,Ember Data,我使用.findQuery().get('length')获取模型中可用于特定过滤的记录总数 但每次它都显示结果为0 我已经列出了我的代码 我尝试过使用.find执行相同的操作,但仍然显示出相同的结果: 请检查一下 如何根据过滤标准计算记录长度? 请检查一下 这里我试图计算接触类型的长度。 有人能告诉我怎么计算吗 现在,我已将我的最后一把小提琴更新为。 如果我的模型记录根据过滤进行更改,如何计算记录总数 请参考(点击类型1和类型2过滤数据)。 在这里,我无法根据过滤条件计算总记录。因为您已经在I

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

但每次它都显示结果为0

我已经列出了我的代码

我尝试过使用.find执行相同的操作,但仍然显示出相同的结果: 请检查一下


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

现在,我已将我的最后一把小提琴更新为。 如果我的模型记录根据过滤进行更改,如何计算记录总数

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

因为您已经在
IndexRoute
模型挂钩中获取记录,该挂钩将在返回记录时设置控制器的
内容
属性,因此,您应该在控制器中访问控制器的
内容
属性,并观察其变化:

App.IndexController = Ember.ArrayController.extend({
  total: function() { 
    return this.get('content.length'); 
  }.property('content.length')
});
看看你的工作指南

编辑 如果要在控制器中筛选
联系人类型
,则不应在routes model挂钩中进行筛选,而应返回您拥有的所有记录:

...
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')
});


希望有帮助。

简单的谷歌搜索可能会有所帮助。不,它不起作用。你是什么意思?在您的示例中,您有3个装置,其中2个装置的contacttype设置为
1
,这是您在routes模型挂钩中筛选的属性,因此控制器内容将只包含符合此筛选条件的记录,有意义吗?是,我想列出联系人类型为1的记录的总长度和联系人类型为2的记录的总长度。使用JSFIDLE编辑我的答案,这是您的where after吗?@user2625690,您看到更新的小提琴了吗?它在底部显示了长度。我已经看到了,但我还有一个疑问,我在更新的问题中列出了。我想计算联系人类型的长度,请参考。如何根据过滤标准计算记录的长度?请检查:请参考(点击类型1和类型2过滤数据)。在这里,我无法根据过滤条件计算总记录。
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')
});