---
title: "ExtJS 3.2 下拉树"
author: "simen_net"
date: "2010-04-17T10:13:28Z"
tags: []
categories: ["Web前端"]
slug: "extjs-3-2"
draft: false
lastmod: "2010-04-17T10:13:28Z"
id: 646019
url: "https://simen-net.iteye.com/blog/646019"
---

[Struts2+Spring2.5+Hibernate3(JPA)+ExtJS3基本后台](/blog/553020) 将ExtJS替换为3..2版本后发现下拉数有些异常：之前展开下来树的下级节点时，下拉菜单不会关掉。但是在3.2版本中无论你在弹出的选择框中点击任何部分，包括选中节点、点击空白处以及点击展开下级节点，弹出框都会自动关闭。查看源代码发现有一部分代码的修改比较困惑：

3.1版本中Combo.js的部分代码

```
onViewClick : function(doFocus){
    var index = this.view.getSelectedIndexes()[0],
        s = this.store,
        r = s.getAt(index);
    if(r){
        this.onSelect(r, index);
    }else if(s.getCount() === 0){
        this.onEmptyResults();
    }
    if(doFocus !== false){
        this.el.focus();
    }
},
onEmptyResults : function(){
    this.collapse();
},
```

3.2版本中Combo.js的部分代码

```
onViewClick : function(doFocus){
    var index = this.view.getSelectedIndexes()[0],
        s = this.store,
        r = s.getAt(index);
    if(r){
        this.onSelect(r, index);
    }else {
        this.collapse();
    }
    if(doFocus !== false){
        this.el.focus();
    }
},
```

 相比之下这里没有进行if(s.getCount() === 0)的比较，貌似这个是判断store是否存在记录的。个人感觉这应该是3.2的一个Bug。因此修改[ExtJS3 下拉树TreeComboBox的修改](http://www.iteye.com/topic/550201) 在代码中增加

```
// 修复ExtJS3.2中自动关闭下来树的Bug
Ext.override(Ext.form.ComboBox, {
      onViewClick : function(doFocus) {
        var index = this.view.getSelectedIndexes()[0], s = this.store, r = s.getAt(index);
        if (r) {
          this.onSelect(r, index);
        } else if (s.getCount() === 0) {
          this.collapse();
        }
        if (doFocus !== false) {
          this.el.focus();
        }
      }
    });
```