无法使用 store.getById() 从存储中读取模型记录

Unable to read Model Records from store by using store.getById()

本文关键字:存储 读取 记录 模型 store getById      更新时间:2023-09-26

我正在尝试为我的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']
        }
});

杰伦响应

{"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));
});

控制台.log

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

尝试使用 bundle.data.getMsg()