【问题标题】:How to get value of other column in renderer function in Extjs?如何在 Extjs 的渲染器函数中获取其他列的值?
【发布时间】:2013-11-23 07:04:41
【问题描述】:

我想在一列的渲染器函数中获取同一行中另一列的值。我尝试了一种方法,但没有奏效。这是我的代码:

columns: [
            {id:'id',header: 'ID', width: 30, sortable: true, dataIndex: 'category_id'},

            {header: 'current_level', width: 100, sortable: true, dataIndex: 'current_level'},
            {header: 'complete_code', width: 100, sortable: true, dataIndex: 'complete_code'},
            {header: 'parent_id', width: 100, sortable: true, dataIndex: 'parent_id'},
            {header: 'parent_name', width: 100, sortable: true, dataIndex: 'parent_name'},
            {
                header: 'has_standards', width: 100, sortable: true, dataIndex: 'has_standards',
                renderer: function(val, meta, record, rowIndex) {
                    if (val == 'Yes') {
                        console.log(record.data.category_id);
                    }
                }
            }
        ],

如您所见,我想在 has_standards 列的渲染器函数中获取同一行中的 category_id。但是我的方法是错误的。你能告诉我怎么做吗?

【问题讨论】:

  • record.data.category_id 是正确的。怎么了?有什么错误吗? val == 'Yes' 正确吗?你能发布更多代码吗?

标签: extjs extjs4 extjs4.1


【解决方案1】:

你想使用record.get('category_id') 例如:

           renderer: function(val, meta, record, rowIndex) {
                if (val === 'Yes') {
                    console.log(record.get('category_id'));
                }else{
                    console.log('Value is not "Yes"');
                }
            }

【讨论】:

    【解决方案2】:

    我正在使用 Ext JS 6 (Sencha),我想根据同一网格中另一列的值是否具有特定值,在网格列中显示图像。根据我使用的 Ext JS 版本,我按照 SW4 的解决方案做了一些小的改动,效果很好。谢谢。

    Ext.define('ViewLL.view.main.List', {
    extend: 'Ext.grid.Panel',
    xtype: 'list',
    
    requires: ['App.store.Datastore'],
    
    store:  {type: 'datastore'},
    
    columns: [
            { text: 'Market',
              renderer: function(value, metaData, record, rowIndex) {
               var value = record.get('location');
               if (value == NYC) {
               return '<img src="resources/images/bigApple.jpg"/>';
               }
               else {
               return null;
               }
              }
           },
           { text: 'City', dataIndex: 'location' }
            ]
    

    当 City 列有记录时,这将在网格列中显示图像文件,其值为 NYC。对于所有其他记录,它显示一个空白单元格。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2023-04-08
      • 1970-01-01
      • 2015-02-02
      • 2019-01-05
      • 1970-01-01
      • 1970-01-01
      • 2011-07-31
      • 2021-11-16
      相关资源
      最近更新 更多