我有下面的代碼,它應該創建一個新的項目。代理類型是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