ComboBox.js 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. Ext.define('uas.override.form.field.ComboBox', {
  2. override: 'Ext.form.field.ComboBox',
  3. displayField: 'text',
  4. valueField: 'value',
  5. queryMode: 'local',
  6. // 加载数据后直接将第一行设置为默认值
  7. selectFirstIfNull: false,
  8. onLoad: function (store, records, success) {
  9. var me = this;
  10. if (!me.value && me.selectFirstIfNull && store.getCount()) {
  11. var value = store.first().get(me.valueField);
  12. me.value = me.multiSelect ? [value] : value;
  13. }
  14. // This flag is saying that we need to call setValue to match the value property with the
  15. // just loaded record set and update the valueCollection (and thereby any bound ViewModel)
  16. // with that matched record.
  17. var needsValueUpdating = !me.valueCollection.byValue.get(me.value);
  18. // If not returning from a query, and the value was set from a raw data value, unrelated to a record
  19. // because the displayField was not honoured when calculating the raw value, then we update
  20. // the raw value.
  21. if (success && needsValueUpdating && !me.isPaging && !(store.lastOptions && 'rawQuery' in store.lastOptions)) {
  22. me.setValueOnData();
  23. }
  24. // This synchronizes the value based upon contents of the store
  25. me.checkValueOnChange();
  26. me.isPaging = false;
  27. },
  28. constructor: function(config) {
  29. var me = this;
  30. config = config || {};
  31. if (!config.store) {
  32. config.store = {
  33. fields: [me.displayField, me.valueField],
  34. data: me.options
  35. }
  36. }
  37. me.callParent([config]);
  38. },
  39. setOptions: function(options) {
  40. var me = this, store = me.getStore();
  41. if (null == store) {
  42. me.setStore({
  43. fields: [me.displayField, me.valueField],
  44. data: options
  45. });
  46. } else {
  47. store.loadData(options);
  48. }
  49. }
  50. });