您好,我对 ember 相当陌生并正在探索它,我已经能够对资源进行简单的发布,但它会像这样渲染我的对象
{"person":{"atribute1":"jjj","atribute2":"jjj"}}
有没有办法像自定义序列化程序一样删除“登录”,我的端点通过传递以下形式的对象来工作
{"atribute1":"jjj","atribute2":"jjj"}
谢谢。
最佳答案
我能找到的唯一解决方案是在我之前覆盖createRecord
data[root] = this.serialize(record, { includeId: true });
我删除了 root 的索引并得到了这个:
App.Store = DS.Store.extend({
revision: 11,
adapter : 'App.CustomAdapter'
});
App.CustomAdapter = DS.RESTAdapter.extend({
createRecord: function(store, type, record) {
var root = this.rootForType(type);
var data = {};
data = this.serialize(record, { includeId: true });
this.ajax(this.buildURL(root), "POST", {
data: data,
context: this,
success: function(json) {
Ember.run(this, function(){
if ( this.rootForType(type) == 'login' ) {
return;
}
this.didCreateRecord(store, type, record, json);
});
},
error: function(xhr) {
//HERE to handle login operation failed
this.didError(store, type, record, xhr);
}
});
}
});
也许需要像 withRoot 或类似的属性。
关于ember.js - ember-data 海关序列化,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15126081/