您是否发布了 SDK 2 应用程序的示例,该应用程序向其“Gear”菜单添加了一个条目,并允许用户通过对话框窗口将设置保存到首选项对象?
最佳答案
我最终使用 ExtJS CookieProvider 来保存我的应用程序的状态。通过使用 cookie,设置是针对每个用户的,而且我还针对每个项目进行了设置。我在 App 类中的代码如下所示:
...
sessionKey: function() {
return (this.getContext().get('appID') || 'MyAppName') + ':' + this.getContext().getProject()._ref;
},
session: function() {
if (!this.state)
this.state = Ext.state.Manager.get(this.sessionKey()) || {};
return this.state;
},
saveSession: function(newState) {
var session = this.session();
Ext.apply(session, newState);
Ext.state.Manager.set(this.sessionKey(), session);
},
launch: function() {
Ext.state.Manager.setProvider(Ext.create('Ext.state.CookieProvider'));
...
要使用它,只需调用 this.session() 来获取状态,然后调用 saveSession() 将状态合并回来。效果很好!
它甚至可以在开发模式下工作。请注意,Chrome(和其他浏览器?)不会以 file://模式保存 cookie,除非您 tell it to .
关于javascript - SDK 2 : Example of a settings dialog,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11379902/