我有下面的代码,它应该创建一个新的项目。代理类型是REST。Sencha Model.save发送/0.json到服务器
var inst = Ext.ModelMgr.create({
title: values.title
}, "EntriesModel");
inst.save({
success: function(model) {
console.log(model);
}
});
后保存(),我看到,请求被发送到http://localhost:3000/entries/0.json,而我认为它应该已被送往http://localhost:3000/entries
项模型看起来像这样
Ext.regModel("EntriesModel", {
fields: [
{name: "id", type: "int"},
{name: "title", type: "string"},
{name: "list_id", type:"int"},
{name: "bought", type: "boolean"},
],
proxy: {
type: 'rest',
url: '/entries',
format: 'json',
noCache: true,
reader: {
type: 'json',
root: 'data'
},
writer: {
type: 'json'
},
listeners: {
exception: function (proxy, response, operation) {
console.log(proxy, response, operation);
}
}
}
});
后端是Rails的。
我找到了其他解决方案。将id添加到Url由appendId属性决定。我认为,它不能将ID添加到创建方法中,因为它在REST中没有意义。但是,现在我在发送创建请求之前设置了appendId。 – 2011-03-03 19:50:26