Javascript:undefined不是一个功能 [英] Javascript: undefined is not a function

查看:178
本文介绍了Javascript:undefined不是一个功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的控制器的代码:

This is my code for my controller:

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");
    }
});

在上面的代码中,您可以看到我已经为我附带的图像编写了一个onclick列标题。当我点击该图像时,它应该调用称为sortStore的函数,但它只是继续抛出Uncaught TypeError:undefined is not a function的错误。

In the code above you can see that I have written an onclick for images that I have attached next to column headers. When I click on that image it is supposed to call the function called as sortStore but it just keeps throwing the error called "Uncaught TypeError: undefined is not a function"

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

Please forgive me if I have done some syntax errors, its because I have shortened the code to make it readable. But rest assured everything except sortStore() calling works fine from onclick event works fine.

推荐答案

查看这个小提琴 https://fiddle.sencha.com/#fiddle/536

我将此创建为面板,并将事件侦听器附加到这样的img元素。

I created this as a panel and attached a event listener to the img element like this.

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);
    }

});

这篇关于Javascript:undefined不是一个功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆