gpt4 book ai didi

ember-cli - 断言失败 : ArrayProxy expects an Array or Ember. ArrayProxy,但您传递了对象

转载 作者:行者123 更新时间:2023-12-04 09:05:48 24 4
gpt4 key购买 nike

这是我的代码

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

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 服务器

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

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



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

提前致谢。

最佳答案

最可能的原因是您有一个从 Ember.ArrayController 扩展的 Controller 。而您只返回相应模型中的普通对象。
我遇到了同样的问题并更改了我的 Controller 以扩展 Ember.Controller反而。

关于ember-cli - 断言失败 : ArrayProxy expects an Array or Ember. ArrayProxy,但您传递了对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25351476/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com