从其他文件访问ExtJS网格的列模型

时间:2009-06-18 16:40:21

标签: properties model extjs grid

我有一个ExtJS网格,其中设置了一个按钮。该按钮触发一个函数,该函数被定义到网格页面中包含的其他JS文件中。该函数触发正常,但在该函数中,我想让列计数如下:

grid.getColumnModel().getColumnCount()

问题是我收到的错误如下:grid.getColumnModel不是函数。

在PHP中我会创建一个“global $ ext”然后访问该函数。我怎么能在Ext中这样做?如何从其他文件访问网格?需要定义什么?

谢谢。

3 个答案:

答案 0 :(得分:1)

您是如何定义网格对象的?你这样做了吗?

var grid = new Ext.grid.GridPanel(...);

如果是这样,则网格对象不在全局范围内。删除“var”并查看它是否有帮助。

答案 1 :(得分:1)

这看起来像是一个范围问题。请参见变量scope in JavaScript

基本上,你可以这样做:

my_global_grid = ... // accessible in the current ~global~ context (document, window)
var my_local_grid = ... // accessible only in the function
window.my_window_global_grid = ... // accessible in the same window

答案 2 :(得分:0)

您也可以将网格对象作为参数传递给函数:

function myFunction(arg1,arg2,grid){
   ...
    var count = grid.getColumnModel().getColumnCount();
   ...
}