gpt4 book ai didi

javascript - Ember创建记录错误

转载 作者:行者123 更新时间:2023-11-28 01:06:00 26 4
gpt4 key购买 nike

我正在尝试遵循 Ember getting started guide ,但有一些差异。最值得注意的是,我使用的是预编译模板。这是我得到的,没有肮脏的模板代码:

window.App = Ember.Application.create({
LOG_TRANSITIONS: true,
VERSION: '1.0.0',
ready: function () {
console.log('App version: ' + App.VERSION + ' is ready.');
}
});

App.Store = DS.Store.extend({

//Use fixtures - I've tried this without the extend too
adapter : DS.FixtureAdapter.extend()
});


App.Router.map(function() {
this.route("todos", { path: "/" });
});


App.TodosRoute = Ember.Route.extend({

model: function() {
return this.store.find('todo');
},

renderTemplate: function() {

this.render('todos', {outlet:'main'});
}
});

App.Todo = DS.Model.extend({
title: DS.attr('string'),
isCompleted: DS.attr('boolean')
});

App.Todo.FIXTURES = [
{
id: 1,
title: 'Learn Ember.js',
isCompleted: true
},
{
id: 2,
title: '...',
isCompleted: false
},
{
id: 3,
title: 'Profit!',
isCompleted: false
}];

App.TodosController = Ember.ArrayController.extend({
actions: {
createTodo: function() {

// Get the todo title set by the "New Todo" text field
var title = this.get('newTitle');

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

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

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

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

如您所见,todos 路由将 todos 模板渲染到 main 导出中。所有这些都很完美。但是,我现在遇到的问题是 TodosController 中的 this.store.createRecord 。每次调用它时(我在应用程序的输入字段中按 Enter 键),我都会收到 Uncaught TypeError: undefined is not a function。我知道该函数正在被调用,因为我可以在调用 this.store.createRecord 之前记录控制台输出。我使用的是 ember 1.6.1 版本和 ember-data 0.14 版本,如果有帮助的话。

如果有人对为什么会发生这种情况有任何想法,我将不胜感激。

最佳答案

您需要升级您的 ember-data 版本。如果您使用 Bower 安装它,则可以更改 Bower.json 中的版本 ("ember-data": "~1.0.0-beta.8") 并运行 bower install.

关于javascript - Ember创建记录错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25071169/

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