【问题标题】:EXTjs 3.4.0 render a ID field in grid with NAMEEXTjs 3.4.0 使用 NAME 在网格中呈现 ID 字段
【发布时间】:2014-03-20 13:35:02
【问题描述】:

我有一个 EXTjs 网格,它显示数据库中我的客户表中的一些字段..

Reports.grid.Reports = function(config) {
    config = config || {};
    Ext.applyIf(config,{
        id: 'reports-grid-reports'
        ,url: Reports.config.connectorUrl
        ,baseParams: { action: 'mgr/reports/getList' }
        ,save_action: 'mgr/reports/updateFromGrid'
        ,fields: ['id','name','filename','remark','year','resourceID','typeID','visible']

然后:

{
             header: 'Type ID'
            ,dataIndex: 'typeID'
            ,sortable: true
            ,width: 100

         }

我的 types 表有 typeid 和 name.. 我的网格显示数字,我如何告诉它在表中显示该 id 的对应名称?

我还有一个在更新窗口中使用的组合框:

Reports.combo.Types = function(config) {
    config = config || {};
    Ext.applyIf(config,{          
         name: 'typeID'       
        ,hiddenName: 'typeID'
        ,displayField: 'name'
        ,valueField: 'id'
        ,fields: ['name','id']
        ,listWidth: 380       
        ,pageSize: 20
        ,url: Reports.config.connectorUrl
        ,baseParams: {
                action: 'mgr/reports/gettypelist2', 'combo': true
            }           
    });
    Reports.combo.Types.superclass.constructor.call(this,config);
};
Ext.extend(Reports.combo.Types,MODx.combo.ComboBox);
Ext.reg('combo-modx-types',Reports.combo.Types);

使用 ,displayField: 'name' 使组合显示名称而不是 id.. 我怎样才能在网格中做同样的事情?

【问题讨论】:

    标签: javascript extjs3


    【解决方案1】:

    如果我正确理解了这个问题,我相信您需要自定义 getList 处理器,而不是直接在 ExtJS 中。覆盖 afterIteration() 函数。大致如下:

    public function afterIteration(array $list) {
        $rows = array();
        foreach ($list as $row){
            // This calls a custom getName() function that gets the name from the other table 
            $row['typeID'] = $this->getName($row['id']); 
            $rows[] = $row;
        }
        return $rows;
    }
    

    也许你的 getName() 函数可能是这样的:

    private function getName($id) {
        $otherTable = $this->modx->getObject('TABLE_ALIAS_HERE', array('internalKey' => $id));
        $name = $otherTable->get('name');
        return $name;
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多