0

我有一个 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

         }

我的类型表有 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 .. 我怎样才能在网格中做同样的事情?

4

1 回答 1

0

如果我正确理解了这个问题,我相信您需要自定义 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;
}
于 2014-03-20T05:35:02.483 回答