【发布时间】:2019-08-10 23:41:28
【问题描述】:
在我的 ExtJs 应用程序中,我必须在进行一些编辑后保存商店中的多条记录(与 beaconsCounter 的数量一样多的记录),然后重新加载商店并关闭对话框,但我不知道为什么,什么也没发生。 我是 Extjs 的新手,所以我不知道我的代码中有什么不正确的地方。
onSaveClick: function (button) {
var dialog, store, beaconToSave , window;
var numberOfBeaconPositionated, beaconsCounter, name, uuid, major, minor, originalNameValue;
var arrayOfLong, arrayOfLat, nameString;
window = button.up('window')
dialog = window.down('form');
dialog.updateRecord();
beaconToSave = dialog.getRecord();
store = beaconToSave.store;
numberOfBeaconPositionated = this.lookupReference('beaconNumbers').getValue();
name = beaconToSave.get('name');
uuid = beaconToSave.get('uuid');
major = beaconToSave.get('major');
minor = beaconToSave.get('minor');
latitude = this.lookupReference('beaconLatitude').getValue();
longitude = this.lookupReference('beaconLongitude').getValue();
if((name === "")||(uuid === "")){
Ext.Msg.alert(Strings.errorTitle, Strings.errorFieldMissing, Ext.emptyFn);
}else if ((major === 0)||(minor === 0)){
Ext.Msg.alert(Strings.errorTitle, Strings.errorMajMin, Ext.emptyFn);
}else if((longitude === "0")||(latitude === "0")){
Ext.Msg.alert(Strings.errorTitle, Strings.errorNoBeacons, Ext.emptyFn);
}else{
nameString = name.split("-");
if((name.indexOf('-%min%') >= 0) || (name.indexOf('-%maj%') >= 0) || (name.indexOf('-'+major+'-'+minor) >= 0) || (nameString[1]!=null)) {
originalNameValue=nameString[0];
}else{
originalNameValue = name;
}
uuid = beaconToSave.get('uuid');
major = beaconToSave.get('major');
minor = beaconToSave.get('minor');
latitude = this.lookupReference('beaconLatitude').getValue();
longitude = this.lookupReference('beaconLongitude').getValue();
arrayOfLong = longitude.split(",");
arrayOfLat = latitude.split(",");
store = beaconToSave.store;
beaconsCounter = numberOfBeaconPositionated;
while(beaconsCounter > 0 ){
newRecord = beaconToSave.copy();
name=originalNameValue.concat("-"+major+"-"+minor);
newRecord.set('name',name);
newRecord.set('latitude',arrayOfLat[beaconsCounter-1]);
newRecord.set('longitude',arrayOfLong[beaconsCounter-1]);
newRecord.set('minor',minor);
if ( !store && !Ext.isEmpty(savedStore)){
store = savedStore;
}
if (store) {
if (newRecord.phantom) {
store.add(newRecord);
}
store.sync({
failure: function (batch) {
store.rejectChanges();
savedStore = store;
if ( batch.exceptions[0].getError().status){
if ( batch.exceptions[0].getError().status == 409){
Traccar.app.showError(this.getTitle() + Strings.errorAddDuplicate);
}else if(batch.exceptions[0].getError().status == 400){
Traccar.app.showError(this.getTitle() + Strings.errorAddDatabase);
}else{
Traccar.app.showError(batch.exceptions[0].getError().response);
}
}
},
success: function(){
store.reload();
this.close();
}, scope: window
});
} else {
newRecord.save();
this.closeView();
}
minor++;
beaconsCounter--;
}
}
},
【问题讨论】:
-
商店是如何定义的?你能附上定义/创建代码吗?
-
Ext.define('Traccar.view.dialog.BeaconController', { extend: 'Traccar.view.dialog.BaseEditController', alias: 'controller.beacon', requires: [ 'Traccar.view.BaseWindow', 'Traccar.view.map.LocationSelectionMap' ], -
您附加了控制器代码而不是存储。请附上正确的代码。
-
啊好吧,抱歉,你是这个意思吗? :
Ext.define('Traccar.store.Beacons', { extend: 'Ext.data.Store', model: 'Traccar.model.Beacon', proxy: { type: 'rest', api: { create : 'api/beacons', read : 'api/beacons', update : 'api/beacons', destroy : 'api/beacons' }, writer: { writeAllFields: true } } }); -
“什么都没有发生”意味着没有调用更新/创建?视图没有关闭?记录已添加到商店?
标签: extjs extjs4 sencha-architect