【问题标题】:ExtJS 4 cant check if variable is undefined and alert for errorExtJS 4 无法检查变量是否未定义并警告错误
【发布时间】:2012-05-03 21:05:56
【问题描述】:

我有:

dockedItems: [{
                xtype: 'toolbar',
                store: 'RecordsListStore',
                selModel: {
                    selType: 'cellmodel'
                },

还有几个这样的图标:

},{
                    icon: g_settings.iconUrl + 'view-icon.png',
                    text: 'View',
                    itemId: 'view-selected-record-from-grid',
                    scope: this
                },{

这是在我看来,在我的控制器中,我有一个这样触发的函数:

'#view-selected-record-from-grid' : {
                click: this.onViewRecordClick
            }

问题是我想显示一个警报消息。如果用户在未选择任何内容时单击按钮。在我的函数中,我得到所选项目的信息(如果有的话),如下所示:

onViewRecordClick: function()   {
        /**
     *Getting the id of the record from the selected row
     */
        var id = this.getRecordsListGrid().getSelectionModel().getCurrentPosition().row;
        var rec = Ext.data.StoreManager.lookup('RecordsListStore').getAt(id);
        rec = rec.data.id;

然后我调用我的 Ajax 请求,因此在这两个部分之间我想检查值以及它们是否未定义(单击图标时未选择)以提醒用户注意这一点。但是,如果我只是试试这个:

if(id == undefined) { alert('No selection');}

并在未选择任何内容时单击图标我没有收到警报消息,而是在控制台中收到错误消息

this.getRecordsListGrid().getSelectionModel().getCurrentPosition().row;未定义

仅此而已。我尝试了一些方法来绕过这个问题,因为看起来,函数会在它看到未定义的变量时停止,但仍然找不到有效的解决方案。

谢谢

勒隆

【问题讨论】:

  • 检查 getCurrentPosition() 是否返回 undefined
  • 大声笑,Sha,再次感谢。这样检查就可以正常工作了!再次完美。

标签: javascript extjs


【解决方案1】:

检查getCurrentPosition() 是否返回未定义。

【讨论】:

    猜你喜欢
    • 2017-07-12
    • 2018-09-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-05-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多