我有一个简单的装置:
App.User.FIXTURES = [
{ userid: 1, name: 'George', email: 'george@gmail.com', bio: 'Lorem Ipsum', created: 'Jan 5, 2015' },
{ userid: 2, name: 'Tom', email: 'tom@hotmail.com', bio: 'Lorem Ipsum 2', created: 'Jan 15, 2015' },
{ userid: 3, name: 'Mary', email: 'mary@aol.com', bio: 'Lorem Ipsum 3', created: 'Jan 25, 2015' }
];
我有一个简单的提交:(摘录)
App.AddController = Ember.ArrayController.extend({
actions: {
save: function () {
App.User.createRecord({ id: 4, userid: 4, name: 'Created person', email: 'sdh', bio: 'my bio', created: '6543456' });
我认为这是正确的,因为我不再在createRecord上出现错误,但现在我收到错误,有任何想法吗?我还缺少一个步骤,只是把东西塞进夹具里?
Uncaught TypeError: Object function () {
if (!wasApplied) {
Class.proto(); // prepare prototype...
}
o_defineProperty(this, GUID_KEY, undefinedDescriptor);
o_defineProperty(this, '_super', undefinedDescriptor);
答案 0 :(得分:0)
Kingpin2k是正确的,因为在UserModel上调用createRecord本身是一种使用Ember数据的旧方法。如果您使用的是最新版本,则应从商店对象中调用createRecord
。
这里应该是什么样子:
App.AddController = Ember.ArrayController.extend({
actions: {
save: function () {
//Create a new user
var user = this.store.createRecord('user',{
id: 4,
userid: 4,
name: 'Created person',
email: 'sdh',
bio: 'my bio',
created: '6543456'
});
// Saves the new model, but not needed if you're just using FIXTURES
// Making the call shouldn't throw any errors though and is used in the Guide
user.save();
// Now you can find your record in the store
this.store.find('user', 4).then(function(user){
console.info(user);
});
}
}
});
这是在以下方面测试的:
DEBUG: -------------------------------
DEBUG: Ember : 1.6.0-beta.1+canary.24b19e51
DEBUG: Handlebars : 1.0.0
DEBUG: jQuery : 2.0.2
DEBUG: -------------------------------
我建议您查看"创建新模型实例" Ember入门指南的一部分,因为他们在那里讨论了这个主题:
http://emberjs.com/guides/getting-started/creating-a-new-model/