未捕获的类型错误&从JSP调用EXTJS方法时未捕获的引用错误

时间:2013-12-02 06:41:09

标签: javascript jsp extjs

XTJS代码的一小部分:

Ext.define('MyApp.Alarms.Exporter', {
namespace : undefined,
exportMax : undefined,
pdfLink : undefined,
excelLink : undefined,
totalAlarms : 0,
//UI
windowDialog : undefined,

constructor : function(namespace, pdfLink, excelLink,
        exportMax) {
    this.namespace = namespace;
    this.pdfLink = pdfLink;
    this.excelLink = excelLink;
    this.exportMax = exportMax;
},

setTotalAlarms : function(value) {
    this.totalAlarms = value;
},

doExport : function(format) {
    var url = '';
    var totalAlarms = this.totalAlarms;

    if (totalAlarms > this.exportMax) {
        if (this.exportMax != 0) {
            totalAlarms = this.exportMax;
        }
    }

    if (totalAlarms > 0) {
        if (format == 'pdf') {
            url = this.pdfLink;
        } else {
            url = this.excelLink
        }

        this.show(url, totalAlarms);
    } else {
        Ext.Msg.show({
            title : 'Export Alarms',
            msg : 'There are no alarms to export',
            buttons : Ext.Msg.OK,
            icon : Ext.Msg.INFO
        });
    }
}

});

JSP代码:

使用随机命名空间

创建对象AlarmsExporter
    if (typeof <%= table.getNamespace() %>AlarmsExporter == 'undefined') {
    <%= table.getNamespace() %>AlarmsExporter = Ext.create('MyApp.Alarms.Exporter', '<%=table.getNamespace()%>', '<%=Util.encodeUrl(request, response, table.getPdfLink())%>', '<%=Util.encodeUrl(request, response, table.getExcelLink())%>', '<%= Util.getNumAlarmsExport()%>');
}

调用ext方法doExport()

            <a href="javascript:<%= table.getNamespace() %>AlarmsExporter.doExport('xls');">
           <img src="<%= xlsIcon %>" alt="Save as Excel Spreadsheet">
        </a>
        <a href="javascript:<%= table.getNamespace() %>AlarmsExporter.doExport('pdf');">
           <img src="<%= pdfIcon %>" alt="Save as PDF"/>
        </a>

现在,当我点击这些链接时,我收到的错误是:

Uncaught TypeError: object is not a function 

Uncaught ReferenceError: _mo_navigation_WAR_ManagedObjectsPortlets_INSTANCE_Bk8L_AlarmsExporter is not defined 

1 个答案:

答案 0 :(得分:1)

因为包含.js代码的extjs文件丢失或无法从JSP访问。检查JSP中包含.js或路径是否正确的{{1}}。

我相信这可以解决你的问题。