extjs 记录按所需属性销毁
extjs record destroy by desired property
我正在开发Exjs mvc应用程序。
我有一个 Extjs 模型:
Ext.define('JC.model.File', {
extend: 'Ext.data.Model',
fields: [
{name: 'id', type: 'int'},
{name: 'fileName', type: 'string'},
{name: 'fileSize', type: 'string'},
{name: 'position', type: 'string'}
]
});
和商店:
Ext.define('JC.store.Files', {
extend: 'Ext.data.Store',
model: 'JC.model.File',
proxy: {
url: JC.Util.createUrl('upload/getfiles'),
type: 'ajax',
simpleSortMode: true,
reader: {
type: 'json',
root: 'items',
totalProperty: 'totalCount'
},
api: {
create: '',
read: undefined,
update: undefined,
destroy: JC.Util.createUrl('upload/deletefile')
},
actionMethods:{create: 'POST', read: 'GET', update: 'POST', destroy: 'GET'}
}
});
以及包含以下列的网格面板:
columns: [
{header: 'id', dataIndex: 'id', flex: 1},
{header: 'file name', dataIndex: 'fileName', flex: 1},
{header: 'file size', dataIndex: 'fileSize', flex: 1},
{header: 'position', dataIndex: 'position', flex: 1}, {
xtype: 'actioncolumn', items: [
{
icon: 'css/images/tree/black-trash-16.png', // Use a URL in the icon config
tooltip: 'Delete',
handler: function(grid, rowIndex, colIndex) {
var rec = grid.getStore().getAt(rowIndex);
grid.getStore().destroy(rec);
}
}
]
}
],
在行:
grid.getStore().destroy(rec);
AJAX 请求的创建方式如下:
http://localhost:8084/myserver/deletefile?_dc=1422789950411&id=JC.model.File-6
我希望删除操作请求的 id 是我想要的记录属性 i,即 rec.id
我希望它是int
类型。我希望请求是这样的:
http://localhost:8084/myserver/deletefile?_dc=1422789950411&id=6
我该怎么做?
我已经设置了一个小提琴来复制这个问题。
我只能通过将 destory 操作的 actionMethod 更改为 POST 并在模型上设置 idProperty 来设法做到这一点。
Ext.application({
name: 'Fiddle',
launch: function() {
Ext.define('File', {
extend: 'Ext.data.Model',
idProperty: 'id',
fields: [{
name: 'id',
type: 'int'
}, {
name: 'fileName',
type: 'string'
}, {
name: 'fileSize',
type: 'string'
}, {
name: 'position',
type: 'string'
}]
});
Ext.define('Files', {
extend: 'Ext.data.Store',
model: 'File',
autoLoad: true,
proxy: {
url: 'data1.json',
type: 'ajax',
simpleSortMode: true,
reader: {
type: 'json',
rootProperty: 'items',
totalProperty: 'totalCount'
},
api: {
create: '',
read: 'data1.json',
update: '',
destroy: 'delete.json',
},
actionMethods: {
create: 'POST',
read: 'GET',
update: 'POST',
destroy: 'POST'
}
}
});
var store = Ext.create('Files');
Ext.create('Ext.grid.Panel', {
title: 'Test',
store: store,
columns: [{
header: 'id',
dataIndex: 'id',
flex: 1
}, {
header: 'file name',
dataIndex: 'fileName',
flex: 1
}, {
header: 'file size',
dataIndex: 'fileSize',
flex: 1
}, {
header: 'position',
dataIndex: 'position',
flex: 1
}, {
xtype: 'actioncolumn',
items: [{
icon: 'css/images/tree/black-trash-16.png',
tooltip: 'Delete',
width:50,
handler: function(grid, rowIndex, colIndex) {
var rec = grid.getStore().getAt(rowIndex);
rec.erase();
}
}]
}],
height: 300,
width: 600,
renderTo: Ext.getBody()
});
}
});
// Sample JSON Data
{
"success": true,
"totalCount": 5,
"items": [{
"id": 1,
"fileName": 'file1.png',
"fileSize": 93204,
"position": 1
}, {
"id": 2,
"fileName": 'file2.png',
"fileSize": 93204,
"position": 1
}, {
"id": 3,
"fileName": 'file3.png',
"fileSize": 93204,
"position": 1
}, {
"id": 4,
"fileName": 'file4.png',
"fileSize": 93204,
"position": 1
}, {
"id": 5,
"fileName": 'file5.png',
"fileSize": 93204,
"position": 1
}]
}
我知道
这是一个旧帖子,但是您可以通过在模型中定义proxy.writer来发送所需的模型数据,在代理编写器定义中,您可以定义transform.fn,它将返回要发送到服务器的数据作为model.data:
writer: {
type: 'json',
allDataOptions: {changes: true, critical: true},
partialDataOptions: {changes: true, critical: true},
encode: true,
rootProperty: 'group',
transform: {
fn: function(data, request, isDraft, model) {
if(request) {
if(request.getAction() == 'destroy') {
data.id = me.get('id');
data.type = me.get('type');
}else if(request.getAction() == 'create') {
delete(data.id);
}
}
return data;
}
}
},
相关文章:
- 如何基于多个属性筛选记录并获取计数
- 循环浏览JavaScript对象并记录其属性
- 在ember.js记录上使用toJSON,将其中一个属性设置为null
- 为什么这个JS for在循环中只记录一个属性的键,而不是整个属性
- extjs 记录按所需属性销毁
- 记录未按时加载到组件中的计算属性
- 无法从 javascript 中的对象获取属性,但在记录其父级时可以将其打印到控制台
- 使用用户脚本记录网页动态创建的标记属性
- 在mongoDb中,如果字符串输入与任何数组元素匹配,如何获取整个记录(在这种情况下,数组是记录的属性)
- 在“跨记录”中查找XML属性的最大值
- EmberJS-防止将具有重复属性的记录添加到存储中
- 为什么console.log()和console.dir()记录的对象属性没有'还不存在
- EXT.NET:“;未捕获的类型错误:无法读取属性'数据'未定义的“;将记录添加到存储时
- 如何记录所有元素'的属性
- Jsdoc:如何使用括号符号记录属性
- 不要在Sails.js的collection属性中按id记录排序
- data-pageable'属性不将记录拆分为页
- 如何记录对象属性
- 为什么fetchXml count属性没有限制返回的记录?
- 为什么一些节点属性在我记录它们时显示为未定义?