有没有一种方法可以在本地加载带有最后选择的选项的 Ext JS ComboBox?
Is there a way you can load a Ext JS ComboBox with the last selected option locally?
我希望能够在刷新页面时加载 select 最后在我的 Ext JS ComboBox 中编辑的任何选项。目前使用下面的代码,它每次只加载第一个选项 'all' 。我知道有一个 localStorage 代理,但不确定如何将其实现到此代码中。以下是我的资料:
let stageFilterCombo = Ext.create("Ext.form.field.ComboBox", {
height: 38,
cls: "arrowCls ro-dropdown-ui br-5 stageFilterDropdownUI",
labelAlign: 'left',
itemId: "PACK_STAGE_FILTER_COMBO",
labelSeparator: "",
labelWidth: 15,
originalIdx: 2,
hidden: isPackForEntity,
margin: '0 15',
displayField: "name",
valueField: "value",
editable: false,
width: 190,
name: "groupBy",
value: "all",
store: Ext.create("Ext.data.Store", {
fields: ["name", "value"],
data: [{
"name": "Show : All Packs",
"pickerName": "All Packs",
"value": "all"
}, {
"name": "Show: Ongoing",
"pickerName": "Ongoing",
"value": "ongoing"
}, {
"name": "Show: Completed",
"pickerName": "Completed",
"value": "completed"
}
]
}),
}
假设我 select 'completed',一旦我 return 到此 ComboBox 过滤器所在的位置,我希望它再次加载 'completed'。任何帮助将不胜感激!
您可以为此使用 cookie:
Ext.onReady(function () {
var nextMonth = new Date();
nextMonth.setMonth(nextMonth.getMonth() + 1);
var _myCookie = Ext.util.Cookies.get('ComboLastSelected');
var states = Ext.create('Ext.data.Store', {
fields: ['abbr', 'name'],
data: [{
"abbr": "AL",
"name": "Alabama"
}, {
"abbr": "AK",
"name": "Alaska"
}, {
"abbr": "AZ",
"name": "Arizona"
}
]
});
var combo = Ext.create('Ext.field.ComboBox', {
fieldLabel: 'Choose State',
width: 200,
store: states,
queryMode: 'local',
queryDelay: 100,
displayField: 'name',
valueField: 'abbr',
minChars: 2,
value: _myCookie ? _myCookie : '',
forceSelection: true,
renderTo: Ext.getBody(),
matchFieldWidth: false
});
combo.on('select', function () {
Ext.util.Cookies.set('ComboLastSelected', this.getValue(), nextMonth);
});
});
我希望能够在刷新页面时加载 select 最后在我的 Ext JS ComboBox 中编辑的任何选项。目前使用下面的代码,它每次只加载第一个选项 'all' 。我知道有一个 localStorage 代理,但不确定如何将其实现到此代码中。以下是我的资料:
let stageFilterCombo = Ext.create("Ext.form.field.ComboBox", {
height: 38,
cls: "arrowCls ro-dropdown-ui br-5 stageFilterDropdownUI",
labelAlign: 'left',
itemId: "PACK_STAGE_FILTER_COMBO",
labelSeparator: "",
labelWidth: 15,
originalIdx: 2,
hidden: isPackForEntity,
margin: '0 15',
displayField: "name",
valueField: "value",
editable: false,
width: 190,
name: "groupBy",
value: "all",
store: Ext.create("Ext.data.Store", {
fields: ["name", "value"],
data: [{
"name": "Show : All Packs",
"pickerName": "All Packs",
"value": "all"
}, {
"name": "Show: Ongoing",
"pickerName": "Ongoing",
"value": "ongoing"
}, {
"name": "Show: Completed",
"pickerName": "Completed",
"value": "completed"
}
]
}),
}
假设我 select 'completed',一旦我 return 到此 ComboBox 过滤器所在的位置,我希望它再次加载 'completed'。任何帮助将不胜感激!
您可以为此使用 cookie:
Ext.onReady(function () {
var nextMonth = new Date();
nextMonth.setMonth(nextMonth.getMonth() + 1);
var _myCookie = Ext.util.Cookies.get('ComboLastSelected');
var states = Ext.create('Ext.data.Store', {
fields: ['abbr', 'name'],
data: [{
"abbr": "AL",
"name": "Alabama"
}, {
"abbr": "AK",
"name": "Alaska"
}, {
"abbr": "AZ",
"name": "Arizona"
}
]
});
var combo = Ext.create('Ext.field.ComboBox', {
fieldLabel: 'Choose State',
width: 200,
store: states,
queryMode: 'local',
queryDelay: 100,
displayField: 'name',
valueField: 'abbr',
minChars: 2,
value: _myCookie ? _myCookie : '',
forceSelection: true,
renderTo: Ext.getBody(),
matchFieldWidth: false
});
combo.on('select', function () {
Ext.util.Cookies.set('ComboLastSelected', this.getValue(), nextMonth);
});
});