Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Assertion Failed: ArrayProxy expects an Array or Ember.ArrayProxy, but you passed object

Tags:

ember-cli

This is my code

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

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;

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

In terminal not showing any error when i run this command

$ ember server

but in browser not showing any thing and console showing this error

Uncaught Error: Assertion Failed: ArrayProxy expects an Array or Ember.ArrayProxy, but you passed object

Please suggest me what i m doing wrong, the code is also on github : https://github.com/narayand4/emberjs

thanks in advance.

like image 942
Durgesh Narayan Avatar asked Aug 17 '14 16:08

Durgesh Narayan


2 Answers

The most likely reason for this is that you have a controller which extends from Ember.ArrayController while you only return a plain object in the corresponding model. I had the same issue and changed my controller to extend Ember.Controller instead.

like image 167
vanthome Avatar answered Nov 15 '22 20:11

vanthome


In the related route for this controller, your model method doesn't return an array, as you've indicated by extending an arrayController.

like image 40
Thock Avatar answered Nov 15 '22 20:11

Thock