Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/373.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 无法在extjs中访问this.myvar_Javascript_Variables_Extjs - Fatal编程技术网

Javascript 无法在extjs中访问this.myvar

Javascript 无法在extjs中访问this.myvar,javascript,variables,extjs,Javascript,Variables,Extjs,我动态地向ExtJs网格添加额外的列,所以我将索引存储为类变量。 但这似乎确实有效,如下所示。为什么会这样 for ( var i = 0; i < names.length; i++) { var column = Ext.create('Ext.grid.column.Column', { text : names[i], header : names[i], width : 80, dIndx: i, renderer: function (v

我动态地向ExtJs网格添加额外的列,所以我将索引存储为类变量。 但这似乎确实有效,如下所示。为什么会这样

for ( var i = 0; i < names.length; i++) {
var column = Ext.create('Ext.grid.column.Column', {
    text : names[i],
    header : names[i],
    width : 80,
    dIndx: i,
    renderer: function (val, p, record) {
        var value = record.data.values[this.dIndx];  // doesn't work
        var value = record.data.values[p.column.dIndx];  // this works
    return value ? value : "";
    }
    });
 // add column to grid etc.
for(变量i=0;i
我认为
这是控制器
Ext.grid.Panel
的范围(如果没有其他定义,请参见编辑),这就是为什么它不能使用关键字。无论如何,第二个是更好的解决方案

编辑

正如@kevhender所评论的,可以为渲染器定义一个参数。但是,由于您使用的是其中一个参数,这没有任何意义。无论如何,我没有提到它

编辑2-为什么默认范围是
Ext.grid.Panel

这里是从处理呈现的函数中截取的一个。该方法是私有的,因此未在API中列出。无论如何,这里是。请注意,使用给定范围或所有者容器
column.renderer.call的范围调用呈现器(column.scope | me.ownerCt,//…
视图的所有者是嵌套视图的面板

/**
 * @private
 * Emits the HTML representing a single grid cell into the passed output stream (which is an array of strings).
 *
 * @param {Ext.grid.column.Column} column The column definition for which to render a cell.
 * @param {Number} recordIndex The row index (zero based within the {@link #store}) for which to render the cell.
 * @param {Number} columnIndex The column index (zero based) for which to render the cell.
 * @param {String[]} out The output stream into which the HTML strings are appended.
 */
renderCell: function(column, record, recordIndex, columnIndex, out) {
    //... more code
    if (column.renderer && column.renderer.call) {
        value = column.renderer.call(column.scope || me.ownerCt, fieldValue, cellValues, record, recordIndex, columnIndex, me.dataSource, me);
        if (cellValues.css) {
            // This warning attribute is used by the compat layer
            // TODO: remove when compat layer becomes deprecated
            record.cssWarning = true;
            cellValues.tdCls += ' ' + cellValues.css;
            delete cellValues.css;
        }
    }
    // ... more code

被设置为该函数中的渲染器函数,请在列定义中使用
范围
为渲染器定义
。保存几个字符的另一个技巧是:返回语句可以是
返回值| |“”
回答得好!为什么这指的是面板而不是列?