[英]Delete function does not run in ExtJS 5.1.1
我定義了一個Delete函數,該函數將刪除Gridpanel上的記錄,但是不知何故! 在調試過程中,它進入rec.destroy
部分,然后跳過整個代碼塊; 沒有錯誤,沒有XHR請求,什么都沒有。
我想知道這可能是由於rec
變量未加載而導致的,恰恰相反,它正在獲取所需的數據。
為什么會發生這種情況?
doDeleteEmployee: function () {
var me = this;
var rec = me.getEmployeeForm().getRecord();
Ext.MessageBox.confirm('Confirm Delete User', 'Are you sure you want to delete user ' + rec.get('firstName') + '?', function (btn) {
if (btn === 'yes') {
rec.erase({
success: function(rec, operation) {
console.log('success step one');
me.getStore().load();
console.log('success step two');
Ext.MessageBox.alert('INFO', 'Delete Success');
},
failure: function(rec, operation) {
console.log('this is failure');
Ext.MessageBox.alert('Delete Failure', operation.request.scope.reader.jsonData.msg);
}
});
}
});
}
編輯 (在@ scebotari66建議之后):
定義擦除方法后仍然出現錯誤。 (我已經更新了上面的'doDeleteEmployee'函數)
我有erase
想法,但這是調試過程后的結果:
1.在調試過程中,要rec.erase
並跳過其中的其余塊。 當我嘗試一步一步走時,我注意到了。 它會保留正確的數據,直到ext-debug .js的afterDrop()
函數為止。
2.我已經定義了兩個console.log(正如您將在上面看到的那樣),並且它僅顯示“成功步驟第一步” 。
3.在開發工具的“網絡”選項卡中,有XHR請求,但它以某種方式通過HTTP發送: POST方法並獲得200-OK作為響應。 所以我想,也許我在Model上做錯了,並在下面添加了。
錯誤:
Uncaught TypeError: Cannot read property 'indexOf' of undefined
模型:
Ext.define('Employee.model.EmployeeMdl', {
extend: 'Ext.data.Model',
requires: ['Ext.data.identifier.Sequential'],
identifier: {
type: 'sequential',
seed: 1223334477,
increment: 10
},
fields: [
{name: 'firstName', type: 'string'},
{name: 'lastName', type: 'string'},
{name: 'email', type: 'string'}
],
idProperty: 'id',
proxy: {
type: 'ajax',
headers: {
'Content-Type': 'application/json'
},
api: {
read: 'http://...0.223:8223/orest/employee',
create: 'http://...0.223:8223/orest/employee',
update: 'http://...0.223:8223/orest/employee',
destroy: 'http://...0.223:8223/orest/employee'
},
reader: {
type: 'json'
},
writer: {
type: 'json',
allowSingle: true,
encode: false,
writeAllFields: true
}
}
});
如果要通過代理銷毀記錄,則應使用擦除方法。
destroy方法由Ext.Base的Ext.data.Model繼承,在處理模型時通常不直接調用該方法。
調用此方法以清理對象及其資源。 調用此方法后,不應再使用該對象。
更新
success
回調。 POST
請求是正常的。 這就是ajax代理的工作方式。 如果要自定義此選項,則需要查看actionMethods配置。 操作名稱到HTTP請求方法的映射。 在基本的AjaxProxy中,對於“讀取”操作,這些設置為“ GET”;對於“創建”,“更新”和“破壞”操作,這些設置為“ POST”。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.