我正在使用Json-server测试我的extjs网格中的CURD操作。我已经在json服务器上放置了一些虚拟数据,并且我能够读取、删除、更新和编辑这些数据。但是当我使用我的extjs应用程序创建数据时,我无法删除或编辑该数据,因为自动生成的Id是"nameOfMyModel + autoIncrementNumber“。
我的商店是:
Ext.define('ThemeApp.store.peopleStore', {
extend: 'Ext.data.Store',
model: 'ThemeApp.model.peopleModel',
storeId: 'peopleStore',
pageSize: 500,
autoLoad: true,
autoSync: true
});模式是:
Ext.define('ThemeApp.model.peopleModel', {
extend: 'Ext.data.Model',
fields: [ 'id' ,'title','body'],
proxy: {
type: 'rest',
//format: 'json',
limitParam:"",
filterParam: "",
startParam:'',
pageParam:'',
url:'http://localhost:3000/posts',
api: {
read : 'http://localhost:3000/db',
create: 'http://localhost:3000/posts',
update : 'http://localhost:3000/posts' ,
destroy : 'http://localhost:3000/posts'
},
headers: {'Content-Type': "application/json" },
reader: {
type: 'json',
rootProperty:'posts'
},
writer: {
type: 'json'
}
}
});我正在添加这样的用户:
var UserStore = Ext.getStore('peopleStore');
var user = Ext.create('ThemeApp.model.peopleModel',{title: "Test", body: "Testing" });
user.save(); //POST /users
UserStore.load();删除:
var grid = button.up('gridpanel');
var selection = grid.getView().getSelectionModel().getSelection()[0];
if (selection) {
UserStore.remove(selection);
UserStore.load();
}有人能告诉我为什么我不能删除/更新我通过extjs应用程序生成的记录吗?简单post的Id类似于http://localhost:3000/posts/(number,应用程序生成的记录的Id是http://localhost:3000/posts/ThemeApp.model.peopleModel-1。
我可以在database.json中看到应用程序生成的记录,但是浏览器说这个url不存在。
请指出我的错误
发布于 2015-04-17 13:20:29
您不能删除它们的原因是它们没有被正确创建。首先,要生成顺序ids,请使用
在您的模型中使用identifier: 'sequential',而不是生成数值id,您可以在这里详细阅读它,在这里生成新对象之后,看看是否可以正确地处理它们。
https://stackoverflow.com/questions/29519106
复制相似问题