Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/extjs/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Extjs 为具有数据存储字段值的变量赋值_Extjs - Fatal编程技术网

Extjs 为具有数据存储字段值的变量赋值

Extjs 为具有数据存储字段值的变量赋值,extjs,Extjs,我需要声明一个变量TeacherName,该变量将从数据存储字段'NameT'接收其值 var storeTeacher = new Ext.data.JsonStore({ id: 'IDstoreTeacher', url: 'teacher.php', method: 'POST', base

我需要声明一个变量TeacherName,该变量将从数据存储字段'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;
但在Firebug中,我总是收到以下错误消息:
“未捕获引用错误:未定义名称”

您需要从存储中获取名称,如下所示:

如果要在第一行中显示名称:

var TeacherName = storeTeacher.getAt(0).get('NameT');
如果出现存储为null或其他错误,请使用函数load中的代码:

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

在第一种情况下,我得到一条错误消息:“UncaughtTypeError:无法调用undefined的方法‘get’”。当我使用“storeTeacher.load”解决方案时,Firebug断点告诉我var TeacherName具有正确的值,但其作用域仅在“storeTeacher.load”中,在程序的其余部分中看不到。当我在程序中使用TeacherName varaiable时,给我带来Firebug的错误消息是:“未捕获引用错误:未定义TeacherName”在“storeTeacher.load”之外声明“var TeacherName”