Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Asscociating a store with Ext.menu.Menu

Tags:

extjs

extjs4.1

I am new to extjs.I want to associate a store on selecting a menu item from Ext.menu.Menu. I am using extjs 4.1.0. I searched on the net even went through sencha doc but I couldn't find any way to achieve this.

Is there some way to achieve it?

Thanks in advance.

like image 824
Supereme Avatar asked Nov 08 '12 08:11

Supereme


1 Answers

I'm using a menu with a store in a project. Here's an example:

Ext.define("Ext.ux.menu.DynamicMenu", {
    extend: "Ext.menu.Menu",
    alias: 'widget.dynamicmenu',
    loaded: false,
    loadMsg: 'Loading...',
    store: undefined,
    icon: '',
    constructor: function (config) {
        var me = this;
        Ext.apply(me, config);

        me.callParent();
    },
    initComponent: function () {
        var me = this;
        me.callParent(arguments);
        me.on('show', me.onMenuLoad, me);
        listeners = {
            scope: me,
            load: me.onLoad,
            beforeload: me.onBeforeLoad
        };
        me.mon(me.store, listeners);
    },
    onMenuLoad: function () { var me = this; if (!me.store.loaded) me.store.load(); },
    onBeforeLoad: function (store) { this.updateMenuItems(false); },
    onLoad: function (store, records) { this.updateMenuItems(true, records); },
    updateMenuItems: function (loadedState, records) {
        var me = this;
        me.removeAll();
        if (loadedState) {
            me.setLoading(false, false);
            Ext.Array.each(records, function (record, index, array) {
                me.add({
                    text: record.get('DisplayName'),
                    data: record,
                    icon: me.icon
                });

            });
            me.store.loaded = true;
        }
        else {
            me.add({ width: 75, height: 40 });
            me.setLoading(me.loadMsg, false);
        }
        me.loaded = loadedState;
    }
});

I found this one on the sencha forums if IIRC, but can't find the link anymore. I made some tweaks for icons etc, ...

On the Ext.Array.each(records, .... You'll need to define your own logic, It's depending on your model. My model has a DisplayName which I use to show as text. I also stock my record in a data property I made in the menu item. You're completely free there.

Good luck!

like image 63
Johan Haest Avatar answered Sep 21 '22 20:09

Johan Haest