gpt4 book ai didi

javascript - 记住 selectfield sencha touch

转载 作者:行者123 更新时间:2023-12-03 10:51:59 27 4
gpt4 key购买 nike

如何在sencha touch中存储selectfield,这样当选择一个字段时,任何方法使用的值,但当页面刷新时,它会自动选择上一个选择。

我的代码:

          {
xtype: 'fieldset',
items: [{
xtype: 'selectfield',
id: 'remem',
label: 'MY Label',
store: 'remem',
options: [
{
text: 'Option1',
value: 'a'
},
{
text: 'Option2',
value: 'b'
}]
}]
}

最佳答案

@developer、@jenson 和我建议您应该将该值保存在 cookie 中,以便该值在浏览器刷新之间保持不变。如果我没记错的话,Extjs 在实用程序命名空间中提供了一个 cookie 管理器类。

编辑

对于 Sencha Touch,您实际上应该按照文档 here 使用 LocalStorage 代理。文档中有一个示例,展示了如何保存用户特定信息以供稍后检索(刷新后等)

实际上,我已将其用于我自己的应用程序,通过在我的应用程序中保存用户显示首选项,以便当他们下次登录时,UI 与他们离开时保持一致。

商店:

Ext.define('MyApp.store.UserPreferencesStore', {
extend: 'Ext.data.Store',

requires: [
'MyApp.model.UserPreferencesModel',
'Ext.data.proxy.LocalStorage'
],

config: {
model: 'MyApp.model.UserPreferencesModel',
storeId: 'UserPreferencesStore',
proxy: {
type: 'localstorage',
id: 'userpreferences'
}
}
});

型号

Ext.define('MyApp.model.UserPreferencesModel', {
extend: 'Ext.data.Model',

requires: [
'Ext.data.Field'
],

config: {
fields: [
{
name: 'userPrefKey'
},
{
name: 'userPrefValue'
}
]
}
});

通过此设置,您可以像通常为任何其他商店所做的那样添加记录

store.add({userPrefKey: '01-showMap', userPrefValue: true});

或编辑现有条目

rec = store.findRecord('userPrefKey','01-showMap');
rec.set('userPrefValue',false);

每当您想要保存更改时,您还必须在存储上调用sync(),并且要从本地存储中检索保存的记录,只需像任何其他存储一样调用load()。

请注意,我的代码是为 Touch 2.3 编写的,因此在最新的 2.4.x 版本中可能略有更改。但这肯定会让您上路。

关于javascript - 记住 selectfield sencha touch,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28396760/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com