Javascript 余烬创建记录错误

Javascript 余烬创建记录错误,javascript,web,ember.js,Javascript,Web,Ember.js,我正试着去理解,但是有一些不同。最值得注意的是,我使用的是预编译模板。以下是我得到的,没有肮脏的模板代码: window.App = Ember.Application.create({ LOG_TRANSITIONS: true, VERSION: '1.0.0', ready: function () { console.log('App version: ' + App.VERSION + ' is ready.'); } }); App.

我正试着去理解,但是有一些不同。最值得注意的是,我使用的是预编译模板。以下是我得到的,没有肮脏的模板代码:

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键),我都会得到一个
未捕获类型错误:未定义不是一个函数
。我知道函数正在被调用,因为我可以在调用
this.store.createRecord
之前记录控制台的输出。我使用的是1.6.1版的余烬和0.14版的余烬数据,如果这有帮助的话


如果有人知道为什么会发生这种情况,我将不胜感激。

我认为您应该这样定义应用程序适配器:

App.ApplicationAdapter = DS.FixtureAdapter.extend();
而不是

App.Store = DS.Store.extend({

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

您需要升级您的余烬数据版本。如果您是用bower安装的,您可以在您的bower.json(
“ember data”):“~1.0.0-beta.8”
)中更改版本,然后运行
bower安装

,我已经尝试过了,但它会给我一个未捕获的类型错误:尝试注册未知工厂:
store:main
,而且ember甚至不加载…只是为了确定,您是否包括了ember data.js?是的,我将jquery、handlebar、ember和ember数据连接到了lib.js中。除此之外,我的
this.store.find('todo')
功能与路线中预期的一样:(是的,就是这样。谢谢!