我已經定義了刪除功能,它將刪除在Gridpanel上的記錄,但不知何故它什麼也不做!在調試過程中,會出現rec.destroy
部分,然後跳過整個代碼塊;沒有錯誤,沒有XHR請求,只是沒有。刪除功能不能在ExtJS 5.1.1中運行
我想知道這可能是因爲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);
}
});
}
});
}
EDIT(只是@ scebotari66的建議後):
仍然得到錯誤之後限定擦除方法。 (我已經更新上面的「doDeleteEmployee」功能)
我有想法erase
但這種調試過程後的結果:
1.在調試過程中,涉及到rec.erase
並跳過剩下的塊,內。當我嘗試着一步一步的時候,我注意到了;它保持正確的數據,直到afterDrop()
函數ext-debug .js。
2.我已經定義了兩個console.log - 你會注意到上面 - 它只顯示'成功的第一步'。
3.在Dev-Tool's的Network選項卡中,有XHR請求,但它以HTTP發送:POST方法並獲得200-OK作爲響應。所以我想,也許我正在做一些錯誤的模型,並在下面添加。
錯誤:
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
}
}
});
親愛的@ scebotari66感謝您的回覆。我更新了代碼片段的一些信息。希望你有時間檢查它。 –
你如何創建記錄。您是單獨加載它,還是在加載商店時創建它? – scebotari66
我想刪除數據庫上創建的記錄。所以記錄會在我加載商店時創建。 –