成员数据:如何正确POST



我已经用ember数据作为持久性处理程序建立了一个ember.js客户端。从数据库中提取所有记录可以很好地使用以下代码:

router.js

App.ProjectsRoute = Ember.Route.extend({
model: function() {
return this.store.find('project');
}
});

但是添加新记录不能正确使用此代码。它只是添加到模型中,而不是持久化。

index.html(示例)

{{input type="text" id="newTitle" value=Title}}
<button class="small" {{action 'createProject'}}><i class="icon-plus-sign"></i></button>

Controller.js

App.ProjectsController = Ember.ArrayController.extend({
actions: {
createProject: function () {
var project = this.store.createRecord('project', {
project_number: this.get('newProject_number'),
title: this.get('newTitle'),
client: this.get('newClient'),
comment: this.get('newComment'),
xmlfile: this.get('newXmlfile')
});
this.set('newProject_number', '');
this.set('newTitle', '');
this.set('newClient', '');
this.set('newComment', '');
project.save();
}
}
});

models.js

App.Project = DS.Model.extend({
title: DS.attr('string'),
client: DS.attr('string'),
comment: DS.attr('string'),
project_number: DS.attr('string'),  
});

app.js

window.App = Ember.Application.create();
App.store = DS.Store.extend({
adapter: DS.RESTAdapter,
});
DS.RESTAdapter.reopen({
namespace: 'api/index.php',
headers: {
"API_KEY": "secret key",
"ANOTHER_HEADER": "Some header value"
}
});

框架版本

Ember : 1.2.0; 
Ember Data : 1.0.0-beta.5+canary.e120006;
Handlebars : 1.1.2; 
jQuery : 2.0.3; 

我错过了哪些配置?但是控制台中没有错误。REST Api可以很好地处理curl。

问题是指向API的JSON"POST"的结构:

发送:

{project: {client: "test",comment: "test",project_number: "test",title: "test"}}

API-后端预期:

{client: "test",comment: "test",project_number: "test",title: "test"}

我想知道我在哪里可以找到ember数据如何构建其请求的信息。(用于进一步开发)

最新更新