0

私はまだextjsの特定の側面を理解しようとしているので、これがあまり意味をなさない場合はご容赦ください..ページがロードされたときにメニューを動的にフェッチしようとしています。しかし、私の MenuFetch() 関数が呼び出されないようです。

ここに私のコードとここにページがあります: http://srikanthrajan.com/test/

    Center = Ext.create('Ext.panel.Panel', {
        title: "User Admin",
        region: 'center',
        layout: 'fit',
        dockedItems: {
            xtype: 'panel',
            dock: 'left',
            title: 'Main Menu',
            width: 160,
            layout: 'anchor',
            collapsible: true,
            collapseDirection: 'left',
            items: [
                {
                    defaults: {
                        width: 140,
                        layout: 'vbox',
                        xtype: 'linkbutton'
                    },
                    id: 'MainMenu',
                    xtype: 'panel',
                    listeners: {
                        load: function(menu) {
                            menu.show()
                            MenuFetch()
                            this.load()
                        }

                    }
                }
            ]
        }
});

//function that uses ajax to fetch menu items and add them
function MenuFetch() {
    Ext.getBody().mask('loading')
    var menu = Ext.ComponentManager.get('MainMenu')

    menu.removeAll(true)    
    Ext.Ajax.request({
        url: 'PanelScripts/getMenu.php',
        method: 'POST',

        callback: function(opt, success, response) {
            var text = response.responseText;
            var obj = Ext.JSON.decode(text);
            if (success && !obj.failure) {
                menu.add(obj)
                Ext.getBody().unmask()
                menu.show()
            } else {
                obj = Ext.JSON.decode(response.responseText);
                Ext.Msg.alert('Error',obj.Error)
                Ext.getBody().unmask()
            }
        }
    });
}

PS: ロード リスナーが必要かどうかもわかりません。基本的に、メニュー項目を json 形式で取得する menuftech 関数を呼び出す必要があります。

4

1 に答える 1

0

Use the Ext.ComponentLoader (or loader config property) to load remote content for the menu. It seems like the xtype should be 'menu' instead of 'panel' based on what you are trying to accomplish. Try something like this:

var adminPanel = Ext.create('Ext.panel.Panel', {
    title: 'User Admin',
    region: 'center',
    layout: 'fit',
    dockedItems: {
        xtype: 'panel',
        dock: 'left',
        title: 'Main Menu',
        width: 160,
        layout: 'anchor',
        renderTo: Ext.getBody(),
        items:[
              {
                 xtype: 'menu',
                 width: 100,
                 loader: {
                     url: 'foo.bar',
                     autoLoad: true,
                     callback: function(loader, success, response, options) {
                         var menu = adminPanel.down('menu');
                         if (success) {
                           menu.add(response.items);
                           menu.show();
                         }
                     },
                     scope: this
                 }
             }
         ]
     }
 });
于 2012-07-24T07:01:02.760 に答える