ExtJS:重写关联股票获取程序

ExtJS:重写关联股票获取程序,extjs,model,associations,has-many,extjs4.2,Extjs,Model,Associations,Has Many,Extjs4.2,我希望覆盖关联(hasMany、belongsTo、hasOne)附带的getter方法。在创建实际getter的地方似乎有点神奇,在查看代码之后,我真的不确定从哪里开始。我看了一下,但无法推断getter是在哪里创建的 比如说,我和很多人的关系是这样的: hasMany: [ {associationKey: 'services', name: 'getServicesStore', model: 'Service'}, {associationKey: 'standards', na

我希望覆盖关联(hasMany、belongsTo、hasOne)附带的getter方法。在创建实际getter的地方似乎有点神奇,在查看代码之后,我真的不确定从哪里开始。我看了一下,但无法推断getter是在哪里创建的

比如说,我和很多人的关系是这样的:

hasMany: [
  {associationKey: 'services', name: 'getServicesStore', model: 'Service'},
  {associationKey: 'standards', name: 'getStandardsStore', model: 'Standard'}
]
hasOne: [
  {associationKey: 'standard', getterName: '_getStandardModel', model: 'Standard'}
],
hasMany: [
  {associationKey: 'services', name: '_getServicesStore', model: 'Services'}
],

/**
 * Getter: returns the associations' Standard model
 * @return {Standard} standardModel
 */
getStandardModel: function() {
  var standardModel = this._getStandardModel();
  if (!standardModel) {
    this.logError('standardModel is undefined');
  }
  return standardModel ;
},

/**
 * Getter: returns the associations' Services store
 * @return {Services} servicesStore 
 */
getServicesStore: function() {
  var servicesStore = this._getServicesStore();
  if (!servicesStore) {
    this.logError('servicesStore is undefined');
  }
  return servicesStore ;
}
当我调用
getServicesStore
getStandardsStore
方法时,我想向控制台输出一些东西,但我希望这两个方法输出相同的东西,因此我希望它们仍然从同一个Associations类继承,但在某个地方重写Associations代码

我知道我的示例可能有点傻,但除了控制台日志记录之外,我还有其他计划。如果有人能提供任何关于从哪里开始的指导,我将不胜感激


Mitchell Simoens的交叉帖子对我的Sencha帖子发表了如下评论:

getter方法是为您生成的,而不是 可以很容易地覆盖。对于HasMany,它是在 createStore,for HasOne/BelongsTo位于createGetter中。这两个 方法返回一个函数,该函数很难重写以进行添加 日志或自定义代码

因此,我的同事和我创建了“私有”getter名称,并仅在该模型中使用,如下所示:

hasMany: [
  {associationKey: 'services', name: 'getServicesStore', model: 'Service'},
  {associationKey: 'standards', name: 'getStandardsStore', model: 'Standard'}
]
hasOne: [
  {associationKey: 'standard', getterName: '_getStandardModel', model: 'Standard'}
],
hasMany: [
  {associationKey: 'services', name: '_getServicesStore', model: 'Services'}
],

/**
 * Getter: returns the associations' Standard model
 * @return {Standard} standardModel
 */
getStandardModel: function() {
  var standardModel = this._getStandardModel();
  if (!standardModel) {
    this.logError('standardModel is undefined');
  }
  return standardModel ;
},

/**
 * Getter: returns the associations' Services store
 * @return {Services} servicesStore 
 */
getServicesStore: function() {
  var servicesStore = this._getServicesStore();
  if (!servicesStore) {
    this.logError('servicesStore is undefined');
  }
  return servicesStore ;
}
我们认为这是我们使用的最佳实践