0
我在计算器上的第一个问题,不要怪我太多;)ExtJS的4 - 显示的值,而不是它是一个组合框里面ID的网格内
我所要做的,显示网格的界面加载内容和ajax请求。
在这一点上,没有什么困难,我设法创建了一个模型,一个商店和一个代理服务器,以便从我的php/mysql脚本中获取值并将它们显示在网格上。
但是在返回的数据中,我有一些ID应该被转换为存储在另一个MySQL表中的等价值。
在这一点上,我卡住了,搜索了几个小时后,我仍然不明白如何重新映射我有一个标签从另一个商店/模型的id值。
下面是代码:
面板视图:
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()
}
});
商店生成器(使用代理):
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'
});
}
});
型号:
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'
}]
});
的值I想翻译的是“slo_ hou_id“仍然显示'1'而不是'Peak'。
在此先感谢您的帮助!
PS:我是很新的ExtJS的...
编辑:
我创建了一个新的商店我的其他表值:
Ext.define('Audiotel.models.HoursModel', {
extend : 'Ext.data.Model',
alias : 'Hours',
fields : [{
name : 'hou_id',
type : 'int'
}, {
name : 'hou_label',
xtype : 'string'
}]
});
而且我已经加载数据到它:
[{"hou_id":"1","hou_label":"Heures pleines"},{"hou_id":"2","hou_label":"Heures creuses"},{"hou_id":"3","hou_label":"Heures nuit"}]
但是,当我尝试搜索为值h时,它似乎失败:
var hours = Audiotel.stores.StoreBuilder.factory('Hours').createStore('getHoursValues');
console.log(hours.getById(1));
console.log(hours.findRecord('hou_id', 1));
所有退货空... :(
感谢您的快速回答,但似乎我仍然失去了一些东西......我更新我的原始问题以添加信息。 ps:我不能直接返回值,因为我需要索引后... – Lemmings 2012-07-09 13:01:54