2013-10-26 5 views
0

Я пытаюсь добиться i18n для моего приложения Sencha Ext JS. Я использовал impl с [https://github.com/elmasse/Ext.i18n.Bundle-touch/blob/master/i18n/Bundle.js][1], но с более упрощенной версией.Невозможно прочитать записи модели из магазина с помощью store.getById()

В принципе, у меня есть магазин [webUi.util.rb.ResourceBundle], связанный с моделью [webUi.util.rb.model.KeyValPair], пытаясь загрузить данные json в магазин. После загрузки данных я пытаюсь получить доступ к загруженным данным через различные функции хранилища. Но не получить его ..? Может ли кто-нибудь найти то, что мне не хватает ..?

класс Магазин

Ext.define('webUi.util.rb.ResourceBundle', { 
     extend: 'Ext.data.Store', 
     requires: [ 
        'webUi.util.rb.model.KeyValPair' 
     ], 
     constructor: function(config){ 
      config = config || {}; 
      var me = this; 
      Ext.applyIf(config, { 
        autoLoad: true, 
        model: 'webUi.util.rb.model.KeyValPair', 
        proxy:{ 
          type: 'ajax', 
          url: webUi.util.AppSingleton.uiRsrcUrl, 
          noCache: true, 
          reader: { 
            type: 'json', 
            rootProperty: 'bundle' 
          }, 
          getParams: Ext.emptyFn 
        }, 
        listeners:{ 
          'load': this.onBundleLoad, 
          scope: this 
        } 
      }); 

      me.callParent([config]); 
      me.getProxy().on('exception', this.onBundleLoadException, this, {single: true}); 
     }, 

     onBundleLoad: function(store, record, success, op) { 
      if(success){ 
       this.fireEvent('loaded'); 
      } else{ 
       this.fireEvent('loadError'); 
      } 
     }, 
     onBundleLoadException: function(){ 
      console.dir(arguments); 
     }, 
     onReady: function(fn){ 
      this.readyFn = fn; 
      this.on('loaded', this.readyFn, this); 
     }, 
     getMsg: function(key){ 
      return this.getById(key)? Ext.util.Format.htmlDecode(this.getById(key).get('val')) : key + '.undefined'; 
     } 
}); 

Модель Класс

Ext.define('webUi.util.rb.model.KeyValPair', { 
     extend: 'Ext.data.Model', 
     config: { 
       idProperty: 'key', 
       fields: ['key', 'val'] 
     } 

}); 

JSON ответ

{"bundle":[{"key":"one","val":"Oneee"},{"key":"two","val":"Twooo"}]} 

мой код

var bundle = Ext.create('webUi.util.rb.ResourceBundle'); 
bundle.onReady(function(){ 
    console.log('%%%%%%%%%%%%%'); 
    console.log(bundle.getMsg('one')); 
    console.log(bundle.getById('one')); 
    console.log(bundle.getAt(0)); 
}); 

console.log

%%%%%%%%%%%%% 
one.undefined 
null 
constructor {raw: Object, modified: Object, data: Object, hasListeners: HasListeners, events: Object…} 

ответ

Смежные вопросы