Описываю класс Manager. Хочу, чтобы при объявлении нового екземпляра без указания id создаваля пустой класс (все поля пустые), если при создании указать id, - лезем в MySQL базу и тащим оттуда нужную запись.
Код:
Ext.define('Classes.Manager', {Проблема в том, что при успешном запросе, console.log(this) выдает совсем не то, что я ожидаю. Как объекту передать то, что вернул ajax?
alias: 'Manager',
config: {
id: null,
name: '',
login : '',
password: '',
},
constructor: function(id) {
if (id) {
Ext.Ajax.request({
url: '/api.php?section=manager&action=get&id=' + id,
success: function(response, options){
jsonResponse = Ext.decode(response.responseText);
if (jsonResponse.status) {
this.id = jsonResponse.response.manager.id;
this.name = jsonResponse.response.manager.name;
this.login = jsonResponse.response.manager.login;
this.password = jsonResponse.response.manager.password;
console.log(this);
} else {
console.log(jsonResponse.response.message);
}
},
failure: function(response, options){
console.log(response);
},
});
} else {
this.id = null;
this.name = '';
this.login = '';
this.password = '';
}
},
});