无法使用store.getById()从商店读取模型记录

时间:2013-10-26 17:31:11

标签: javascript json extjs

我正在尝试为我的sencha Ext JS应用程序实现i18n。 我使用了[https://github.com/elmasse/Ext.i18n.Bundle-touch/blob/master/i18n/Bundle.js] [1]中的impl,但更简化了版本。

基本上,我有一个商店[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…}

1 个答案:

答案 0 :(得分:0)

尝试使用bundle.data.getMsg()

相关问题