gpt4 book ai didi

javascript - 断言失败 : The value that #each loops over must be an Array error. 我做错了什么?

转载 作者:行者123 更新时间:2023-11-30 00:28:44 25 4
gpt4 key购买 nike

我正在学习 Ember 的 TodoMVC 教程,但我被卡住了。基本上,我定义了 2 个 Controller 。这是 todos.js

import Ember from "ember";

export default Ember.ArrayController.extend({
actions:{
createTodo: function(){
var title = this.get("newTitle");

if(!title){
return false;
}
if(!title.trim()){
return;
}

var todo = this.store.createRecord("todo", {
title: title,
isCompleted: false
});

// Clear text field
this.set('newTitle', '');

todo.save();
}
}
})

这是 todo.js

import Ember from "ember"

export default Ember.ObjectController.extend({
isCompleted: function(key, value){
var model = this.get("model");

if(value === undefined){
return model.get("isCompleted");
} else {
model.set('isCompleted', value);
model.save();
return value;
}
}.property('model','model.isCompleted')
});

这里是 routes/todos.js

import Ember from "ember";

export default Ember.Route.extend({
model: function() {
return this.store.find("todo");
}
});

最后,还定义了todos.hbs

<ul id="todo-list">
{{#each todo in model itemController="todo"}}
<li {{bind-attr class="todo.isCompleted:completed"}}>
{{input
type="checkbox"
class="toggle"
checked=todo.isCompleted
}}
<label>{{todo.title}}</label><button class="destroy"></button>
</li>
{{/each}}
</ul>

一切看起来都很好,但我在控制台中收到以下错误:

Uncaught Error: Assertion Failed: The value that #each loops over must be an Array. You passed todomvc-embercli@controller:array:, but it should have been an ArrayController

我在这里做错了什么?

最佳答案

根据 turboMaCk's comment ,从 package.json 中删除 ember-disable-proxy-controllers 似乎解决了这个问题。

关于javascript - 断言失败 : The value that #each loops over must be an Array error. 我做错了什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30425055/

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