0

这是一段代码,在创建我的网格后立即插入,在 2.0 下运行良好:

var gridFilter = Ext.get(gridToolbar.addDom({ tag: "input", 
    type: "text", 
    size: "25", 
    value: "", 
    cls: "x-grid-filter"}).el);
gridFilter.on("focus", function(){this.dom.select();}); 

现在,我在第二个语句中得到一个 JavaScript 错误:“gridFilter is null”。

我是否错过了一些关于 3.0 向后兼容性的重要警告?

这改编自 Ext JS 网站上的示例代码,所以我不认为我在做一些非常深奥的事情。

除了上述之外,gridToolbar 工作正常,并且第一行添加到工具栏的输入字段确实出现在浏览器中。因此,我认为 addDom() 或 Ext.get() 必须与破坏我的代码的某些东西根本不同。

4

2 回答 2

0

由于我看不到您的所有代码,我的猜测是您的代码不尊重在调用 addDom() 之前必须呈现工具栏,并且代码在 Ext2 中“意外”工作。此版本不兼容的一个原因可能是 ext 版本之间的渲染方式发生了变化。在 Ext2 中渲染的内容可能尚未在 Ext3 中渲染。

您可以尝试的示例修复:

gridToolbar.on("render", function() {

    var gridFilter = Ext.get(gridToolbar.addDom({ tag: "input", 
        type: "text", 
        size: "25", 
        value: "", 
        cls: "x-grid-filter"}).el);

    gridFilter.on("focus", function(){this.dom.select();});

});
于 2009-07-28T12:11:52.527 回答
0

我想出了如何让它再次工作:

function getGridFilterBox(filterid, width, defaultvalue) {
    // Returns a basic filter box that can be used to filter a grid
    return {
        id: filterid,
        tag:    'input',
        type:   'text',
        size:   width || 25,
        value:  defaultvalue || '',
        cls:    'x-grid-filter'
        }
    }

function SetupGridFilter(filterid, gridToReload, ds) {
    // Sets up the keyboard and parameter filtering for a basic filter box on a grid toolbar
    var filter = Ext.get(filterid);
    filter.on('keyup', function(e) {
        var key = e.getKey(); // ENTER key filters, as does backspace or delete if the value is blank
        if((key== e.ENTER)||((key == e.BACKSPACE || key == e.DELETE) && this.getValue().length == 0)) { reloadGrid(gridToReload); }
        });
    filter.on('focus', function(){this.dom.select();}); // setup an onfocus event handler to cause the text in the field to be selected
    ds.on('beforeload', function() { ds.baseParams.searchPhrase = filter.getValue(); });
    }

然后,在其他地方,在视口规范的中间:

thisGrid = new Ext.grid.GridPanel({
   tbar: new Ext.Toolbar({items: ["-",
       getGridFilterBox("myfilter")] }),
   })

最后,在视口之后:

thisGrid.show();
SetupGridFilter("myfilter", thisGrid, gridData);
于 2009-07-31T15:45:00.893 回答