Extjs Javascript:undefined不是一个函数

Extjs Javascript:undefined不是一个函数,extjs,sencha-touch,Extjs,Sencha Touch,这是我的控制器代码: Ext.define(controller.details.StudentControlller', { extend: 'Ext.app.Controller', requires: [ ], config: { }, Init: function(){ "use strict"; var me = this; this.app = this.getApplication(); this.create

这是我的控制器代码:

Ext.define(controller.details.StudentControlller', {
    extend: 'Ext.app.Controller',
    requires: [
    ],
    config: {
},
Init: function(){
"use strict";
        var me = this;
        this.app = this.getApplication();
    this.createStudentTables();
}
createStudentTables: function () {
var finalStudent=[],
view=this.getStudentsTableView();

arrReqTplTest = ['<div class="StuReq"><table><tr><th class=" StuReq ">' +
                'NAME  ' +
                '<img src="resources/images/arrow-bottom-1-512.png" width="10px" height="10px" onclick="this.sortStore();"/>' +
                '</th><th class=" StuReq ">CATEGORY ' +
                ' <img src="resources/images/arrow-bottom-1-512.png" width="10px" height="10px" onclick="sortStore();"/>' +
                '</th><th class=" StuReq ">STUDENT GROUP  ' +
                '<img src="resources/images/arrow-bottom-1-512.png" width="10px" height="10px" onclick="sortStore();"/>' +                
</th></tr></table></div>'];
finalStudent.push({
title: “Student Table”,
                collapsed: true,
                layout: 'fit',
                items: [
                    {
                        xtype: 'component',
                        itemId: 'StudentTablViewID-' + i,
                        html: arrReqTplTest

                    },
                    {
                        xtype: 'dataview',
                        itemId: 'StudentTable-' + i,
                        height: 200,
                        store: ‘studentDetailStore’,
                        //itemHeight: 70,
                        scrollable: false,           
                        itemSelector: 'div.wrap-requirements-' + i
                    }
                ]
            });
        }

        view.add(finalStudent);
})
}
sortStore: function(){
        alert("Now it is finally undefined");
    }
});
Ext.define(controller.details.studentcontroller'{
扩展:“Ext.app.Controller”,
要求:[
],
配置:{
},
Init:function(){
“严格使用”;
var me=这个;
this.app=this.getApplication();
这是.createStudentTables();
}
createStudentTables:函数(){
var finalStudent=[],
view=this.getStudentsTableView();
arrReqTplTest=[“”+
“姓名”+
'' +
“类别”+
' ' +
“学生团体”+
'' +                
'];
最后一名学生({
标题:“学生表”,
对,,
布局:“适合”,
项目:[
{
xtype:'组件',
itemId:'StudentTableViewId-'+i,
html:arrReqTplTest
},
{
xtype:“数据视图”,
itemId:'StudentTable-'+i,
身高:200,
store:'studentDetailStore',
//身高:70,
可滚动:false,
itemSelector:“div.wrap-requirements-”+i
}
]
});
}
查看。添加(最终学生);
})
}
sortStore:函数(){
警报(“现在它最终未定义”);
}
});
在上面的代码中,您可以看到我为附加在列标题旁边的图像编写了onclick。当我点击该图像时,它应该调用名为sortStore的函数,但它只是不断抛出名为“UncaughtTypeError:undefined不是函数”的错误


请原谅我,如果我做了一些语法错误,这是因为我缩短了代码,使其可读性。但请放心,除了从onclick事件调用sortStore()之外,其他一切都可以正常工作

问题是您正在用字符串绑定侦听器。只有在全局级别(窗口)上有函数
sortStore
时,此侦听器才会启动。这个监听器永远不会像您预期的那样在当前范围内执行

建议的方法是制作一个
Ext.Img
,并将一个单击侦听器绑定到它。或者使用
xtype:“image”

Ext.create('Ext.Img', {
    src: 'resources/images/arrow-bottom-1-512.png',
    listener: {
        click: function(){ ... }
    }
});
看看这把小提琴

我将其创建为一个面板,并像这样将事件侦听器附加到img元素

Ext.define('test.view.SignupPanel', {
    extend: 'Ext.Panel',
    xtype: 'mypanel',
    config: {
      itemId: 'testItem',
      layout: 'fit',
      html:'<img  src="http://www.sencha.com/img/v2/logo.png"/>',
      listeners:{
        initialize:function(obj){ 
               var me= this;
               obj.element.down('img').on('tap', me.imageTap, this, me);
            }
      }
    },
    imageTap:function(obj){
        Ext.Msg.alert('Hi', this.xtype);
    }
Ext.define('test.view.SignupPanel'{
扩展:“Ext.Panel”,
xtype:“mypanel”,
配置:{
itemId:'testItem',
布局:“适合”,
html:“”,
听众:{
初始化:函数(obj){
var me=这个;
obj.element.down('img')。on('tap',me.imageTap,this,me);
}
}
},
imageTap:功能(obj){
Ext.Msg.alert('Hi',this.xtype);
}

}))

你是什么意思,就像我必须做Ext.create。。。。。。。在全局级别上,然后如何将其添加到代码中的html中?如果在全局级别上声明该函数,我调用该函数时是否会失去作用域?嘿,我尝试了你的代码,但没有收到警报。你能在我的部件上试一下吗。这是个问题