简体   繁体   English

ExtJs 4-在网格内的组合框中显示一个值,而不是其ID

[英]ExtJs 4 - Display a value instead of it's id inside a combobox within a grid

my first question on StackOverflow, don't blame me too much ;) 我对StackOverflow的第一个问题,不要怪我太多;)

I've got to do an interface that shows a grid with content loaded from and ajax request. 我必须做一个界面来显示一个网格,其中包含从中加载的内容和ajax请求。

At this point, nothing difficult, I managed to create a model, a store and a proxy in order to get values from my php/mysql script and show them on the grid. 在这一点上,没有什么困难,我设法创建了一个模型,一个存储和一个代理,以便从我的php / mysql脚本中获取值并将它们显示在网格上。

But in the returned data, I have some IDs that should be translated to their equivalent values stored in another MySQL table. 但是在返回的数据中,我有一些ID应当转换为存储在另一个MySQL表中的等效值。

And at this point I'm stuck and after searching for hours, I still don't understand how to remap the id value I have to a label from another store/model. 现在,我陷入了困境,经过几个小时的搜索,我仍然不知道如何将我必须拥有的id值重新映射到另一个商店/模型的标签。

Here is the code : 这是代码:

Panel view : 面板视图:

Ext.define('Audiotel.views.TimeRangePanelView', {
extend : 'Ext.grid.Panel',
config : {
    columns : [{
        header : 'Start date',
        dataIndex : 'slo_time_start',
        editor : {
            xtype : 'timefield',
            format : 'H:i:s',
            increment : 60 // In minutes
        },
        renderer : function(value, metaData, record, rowIndex, colIndex, store, view) {
            return value;
        }
    }, {
        header : 'End Date',
        dataIndex : 'slo_time_end',
        editor : {
            xtype : 'timefield',
            format : 'H:i:s',
            increment : 60 // In minutes
        },
        renderer : function(value, metaData, record, rowIndex, colIndex, store, view) {
            return value;
        }
    }, {
        header : 'Days',
        dataIndex : 'slo_valid_days',
        editor : Ext.create('Ext.form.field.ComboBox', {
            typeAhead : true,
            triggerAction : 'all',
            selectOnTab : true,
            store : [['Everyday', 'Everyday'], ['WE and holiday', 'WE and holiday'], ['Week', 'Week']],
            lazyRender : true,
            listClass : 'x-combo-list-small'
        })
    }, {
        header : 'Range',
        dataIndex : 'slo_hou_id',
        editor : Ext.create('Ext.form.field.ComboBox', {
            selectOnTab : true,
            store : [['1', 'Peak'], ['2', 'Offpeak'], ['3', 'Night']],
            listClass : 'x-combo-list-small',
        }),
        renderer : function(value, metaData, record, rowIndex, colIndex, store, view) {
            return value;
        }
    }],
    height : 400,
    width : '100%',
    store : Audiotel.stores.StoreBuilder.factory('TimeRange').createStore('getDefaultTimeRange'),
    renderTo : "range_table_div",
    frame : true
},

constructor : function() {
    this.callParent()
}
});

Store builder (use a proxy) : 商店构建者(使用代理):

Ext.define('Audiotel.stores.StoreBuilder', {

statics : {
    instance: null,
    factory: function(name) {
        if(!this.instance){
            this.instance = new this({storeName: name});
        }
        return this.instance;
    }
},

storeName: null,

config: {
    storeName: ''
},

constructor: function(config){
        this.initConfig(config);
},

applyStoreName: function(name){
    if(!name){
        throw new Error('['+ Ext.getDisplayName(arguments.callee) +'] Name of store to create.');
    }
    return name;
},


createStore: function(proxyMethod, proxyParams){
    var modelName = Audiotel.utils.AppUtils.BASE_PATH+'.'+Audiotel.utils.AppUtils.MODEL_PATH+'.'+this.getStoreName()+'Model';
    Ext.Loader.syncRequire(modelName);  
    return Ext.create('Ext.data.Store', {
            autoLoad: true,
            proxy: Ext.create('Audiotel.proxies.AudiotelProxyWrapper', {method: proxyMethod, params: proxyParams}).getWrappedProxy(),
            model:  modelName,
            storeId:    this.getStoreName()+'Store'
        });
}
});

Model : 型号:

Ext.define('Audiotel.models.TimeRangeModel', {
extend : 'Ext.data.Model',
alias : 'TimeRange',
fields : [{
    name : 'slo_time_start',
    type : 'string'
}, {
    name : 'slo_time_end',
    xtype : 'string'
}, {
    name : 'slo_valid_days',
    type : 'string'
}, {
    name : 'slo_hou_id',
    type : 'string'
}]
});

The value I want to translate is the "slo_hou_id" wich still shows '1' instead of 'Peak'. 我要转换的值是“ slo_hou_id”,但仍然显示为“ 1”而不是“ Peak”。

Thanks in advance for any help! 在此先感谢您的帮助!

ps : I'm very new to ExtJS... ps:我对ExtJS非常陌生...

edit : 编辑:

I created a new store for my other table values : 我为其他表值创建了一个新商店:

Ext.define('Audiotel.models.HoursModel', {
extend : 'Ext.data.Model',
alias : 'Hours',
fields : [{
    name : 'hou_id',
    type : 'int'
}, {
    name : 'hou_label',
    xtype : 'string'
}]
});

And I've loaded data into it : 我已经将数据加载到其中:

[{"hou_id":"1","hou_label":"Heures pleines"},{"hou_id":"2","hou_label":"Heures creuses"},{"hou_id":"3","hou_label":"Heures nuit"}]

But when I try to search for values, it seems to fail : 但是当我尝试搜索值时,它似乎失败了:

var hours = Audiotel.stores.StoreBuilder.factory('Hours').createStore('getHoursValues');

console.log(hours.getById(1));
console.log(hours.findRecord('hou_id', 1));

All returns null... :( 全部返回null ... :(

You have 2 options: 您有2个选择:

  1. First option is that you return what you want from MySQL, instead of doing the "join" in Javascript: so, from MySQL/PHP, return "Peak" instead of "1". 第一种选择是您从MySQL返回想要的内容,而不是在Javascript中执行“ join”:因此,从MySQL / PHP返回“ Peak”而不是“ 1”。
  2. Use "Store.find*" functions to map "1" to "Peak". 使用“ Store.find *”功能将“ 1”映射到“ Peak”。 Something like other_store.findRecord('slo_hou_id', 1).attribute_you_want . 类似other_store.findRecord('slo_hou_id', 1).attribute_you_want

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM