【发布时间】:2012-12-13 13:49:33
【问题描述】:
如何在一个类中创建静态字段,然后在 Sencha Touch 2 中从该类外部访问它们?
例如,我创建了一个带有单个静态的简单单例:
Ext.define('App.util.Config', {
singleton: true,
statics: {
url: {
USER: 'http://localhost:3436/api/user'
}
},
config: { },
constructor: function (config) {
this.initConfig(config);
this.callParent([config]);
}
});
我无法使用 App.util.Config.url.USER 但使用 App.util.Config.self.url.USER 访问 USER 字段。查看 Sencha 文档上的示例,看来我应该能够以前一种方式访问该字段:
See Statics Section in this link and how they access the Computer.InstanceCount field
【问题讨论】:
-
对我来说工作得很好。 App.util.Config.url 是未定义的吗? App.util.Config.self 返回什么?
-
App.util.Config.url
undefinedApp.util.Config.selffunction () { return this.constructor.apply(this, arguments); }App.util.Config.self.url.USER"http://localhost:3436/api/user" -
另一条可能相关的信息,我不是
Ext.create(...)这个类,但在app.js中需要它requires: [ 'Ext.MessageBox', 'App.data.ConnectionRouter', 'App.util.Config' ],
标签: extjs sencha-touch-2