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

grid.getColumnModel().getColumnCount()

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

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

谢谢。

有帮助吗?

解决方案

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

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

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

其他提示

这看起来像是一个范围问题。请参阅 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

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

function myFunction(arg1,arg2,grid){
   ...
    var count = grid.getColumnModel().getColumnCount();
   ...
}
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top