我正在使用Extjs-6开发Web应用程序。我想从public function getAutoloaderConfig()
{
return array(
'Zend\Loader\StandardAutoloader' => array(
'namespaces' => array(
__NAMESPACE__ => __DIR__ . '/src/' . __NAMESPACE__,
'Testing\Facebookbd' => __DIR__ . '/src/Test/facebook'
),
),
);
}
扩展一个类。我这样做:
Ext.form.field.Picker
我在这个类中的值是一个如下对象:
...
extend: 'Ext.form.field.Picker',
createPicker: function(){
return new Ext.panel.Panel({
items: [{
xtype: 'textfield',
name: 'text',
fielLabel: 'text label'
}, {
xtype: 'colorfield',
name: 'color',
fielLabel: 'color field'
},
...
]
});
}
...
但是当我将此对象设置为类的值时,它在选择器中显示为{
text: 'value of textfield',
color: 'value of colorfield'
}
。
我该怎么办?
让选择器像[object object]
这样的混淆来获取选择器的值然后返回正确的字符串?
答案 0 :(得分:0)
除了模板之外还有更多内容。 下面是textfield + datefield的示例选择器实现,只需将其调整为具有colorfield。
// component has picker with both textfield and datefield;
// when picker is collapsed, data is displayed as "{text}, {date}"
Ext.define('ColorPicker', {
extend: 'Ext.form.field.Picker',
// picker template
config: {
popup: {
lazy: true,
$value: {
xtype: 'window',
closeAction: 'hide',
referenceHolder: true,
minWidth: 540,
minHeight: 60,
layout: 'form',
header: false,
resizable: true,
items: [
{
xtype: 'textfield',
name: 'text',
fielLabel: 'text label',
anchor: '100%',
reference: 'text'
},
{
xtype: 'datefield',
name: 'color',
fielLabel: 'color field',
anchor: '100%',
format: 'd.m.Y',
reference: 'date'
}
],
fbar: [
{ text: 'OK', reference: 'okBtn' },
{ text: 'Cancel', reference: 'cancelBtn' }
]
}
}
},
dateFormat: 'd.m.Y',
createPicker: function(){
var me = this,
popup = me.getPopup();
// the window will actually be shown and will house the picker
me.pickerWindow = popup = Ext.create(popup);
popup.lookupReference('okBtn').on('click', 'onPickerOk', me);
popup.lookupReference('cancelBtn').on('click', 'onPickerCancel', me);
popup.on({
close: 'onPickerCancel',
scope: me
});
me.updateValue(me.getValue());
return popup;
},
// ok picker button handler
onPickerOk: function () {
var me = this,
popup = me.pickerWindow,
textField = popup.lookupReference('text'),
dateField = popup.lookupReference('date'),
value = {
text: textField.getValue(),
date: dateField.getValue()
};
popup.hide();
me.setValue(value);
},
// cancel picker button handler
onPickerCancel: function () {
var me = this,
popup = me.pickerWindow;
popup.hide();
me.updateValue(me.getValue());
},
// override set value to support both string ("{text}, {date}")
// and object ({ text: "{text}", date: "{date}" })
setValue: function(value) {
var me = this,
text,
date,
v;
if (Ext.isObject(value)) {
value = value.text + ", " + Ext.Date.format(value.date, me.dateFormat);
}
me.callParent([ value ]);
// always update in case opacity changes, even if value doesn't have it
// to handle "hex6" non-opacity type of format
me.updateValue(value);
},
// update values in picker fields
updateValue: function (value) {
var me = this,
popup = me.pickerWindow,
textField,
dateField,
text = value.text,
date = value.date;
if (!popup || !popup.isComponent) {
return;
}
if (Ext.isString(value)) {
value = value.split(',');
text = (value[0] || '').trim();
date = Ext.Date.parse((value[1] || '').trim(), me.dateFormat);
} else if (Ext.isObject(value)) {
text = value.text || '';
date = value.date || '';
}
textField = popup.lookupReference('text');
dateField = popup.lookupReference('date');
if (!me.syncing) {
me.syncing = true;
textField.setValue(text);
dateField.setValue(date);
me.syncing = false;
}
}
});