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

Dur*_*yan 5 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;
Run Code Online (Sandbox Code Playgroud)

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

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

$ ember服务器

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

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

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

提前致谢.

van*_*ome 11

最可能的原因是,Ember.ArrayController您只有在相应模型中返回普通对象时才有一个控制器.我遇到了同样的问题,并改变了我的控制器以扩展Ember.Controller.