断言失败:ArrayProxy需要一个Array或Ember.ArrayProxy,但是你传递了对象

时间:2014-08-17 16:58:34

标签: ember-cli

这是我的代码

/ ********************************************** ******** /

import Ember from "ember";

var TodosController = Ember.ArrayController.extend({

actions: {

createTodo: function(){

  // Get the todo title by the "New Todo" input 
  var title = this.get('newTitle');
  if(!title.trim()){ return; }

  // Create the new Todo model
  var todo = this.store.createRecord('todo', {
    title: title,
    isCompleted: false
  });

  // Clear the 'New Todo' input field
  this.set('newTitle', '');

  // Save the new model
  todo.save();
},

clearCompleted: function(){
  var completed = this.filterBy('isCompleted', true);
  completed.invoke('deleteRecord');
  completed.invoke('save');
}
},

remaining: function() {
return this.filterBy('isCompleted', false).get('length');
}.property('@each.isCompleted'),

inflection: function() {
var remaining = this.get('remaining');
return remaining === 1 ? 'todo' : 'todos';
}.property('remaining'),

hasCompleted: function(){
return this.get('completed') > 0;
}.property('completed'),

completed: function(){
return this.filterBy('isCompleted', true).get('length');
}.property('@each.isCompleted'),

allAreDone: function(key, value) {
if(value === undefined){
  return !!this.get('length') && this.everyProperty('isCompleted', true);
} else {
  this.setEach('isCompleted', value);
  this.invoke('save');
  return value;
}

}.property('@each.isCompleted')

});
export default TodosController;

/ ********************************************** ********* /

在运行此命令时终端未显示任何错误

$ ember server

但在浏览器中没有显示任何内容和控制台显示此错误

  

未捕获错误:断言失败:ArrayProxy需要一个数组或   Ember.ArrayProxy,但你传递了对象

请告诉我我做错了什么,代码也在github:https://github.com/narayand4/emberjs

提前感谢。

2 个答案:

答案 0 :(得分:11)

最可能的原因是你有一个从Ember.ArrayController扩展的控制器,而你只返回相应模型中的普通对象。 我遇到了同样的问题,并将我的控制器改为扩展Ember.Controller

答案 1 :(得分:4)

在此控制器的相关路由中,您的model方法不会返回数组,正如您通过扩展arrayController所指示的那样。