Goran
Goran

Reputation: 17

Assign a value to a variable with DataStore fields value

I need to declare a variable TeacherName that will receive its value from the DataStore field 'NameT'

var storeTeacher = new Ext.data.JsonStore({
                         id: 'IDstoreTeacher',
                         url: 'teacher.php',
                         method: 'POST',
                         baseParams:{task: "TEACHERNAME",
                                         parametar: idTeacher},
                         root: 'rows',
                         fields: [{name: 'NameT', type: 'string', mapping: 'teacher_name'}],
                         autoLoad: true 
});
var TeacherName = NameT;

But in Firebug I always get the following error message: "Uncaught ReferenceError: NameT is not defined"

Upvotes: 0

Views: 1396

Answers (1)

Hadas
Hadas

Reputation: 10384

You need to get the nameT from the store, like this:

if you want the name in the first row:

var TeacherName = storeTeacher.getAt(0).get('NameT');

if you get the error that the store is null or something else, use the code in the function load:

storeTeacher.load({ 
    scope: this, 
    callback: function (records, operation, success) { 
        var TeacherName = storeTeacher.getAt(0).get('NameT');
    }
});

Upvotes: 1

Related Questions