I would like to declare a global variable that takes value from DataStore and display its value in the alert Window.
var params = 1;
var storeTeacher = new Ext.data.JsonStore({
id: 'IDstoreTeacher',
url: 'school.php',
method: 'POST',
baseParams:{task: "LABEL",
parametar: params},
root: 'rows',
fields:
[{name: 'NameT', type: 'string', mapping: 'Teacher_name'}],
autoLoad: true
});
var TeacherName;
storeTeacher.load({
scope: this,
callback: function (records, operation, success) {
TeacherName = storeTeacher.getAt(0).get('NameT');
}
});
alert(TeacherName);
But, only thing I get is the alert Window that says: undefined
Your
alert(TeacherName);call is being executed before the callback on yourstoreTeacher.loadcallback is being executed.If you put the
alert(TeacherName)in the callback function it will populate your TeacherName properly and show correctly in the alert:This behavior is expected.