Results 1 to 2 of 2

Thread: Build menu or comboBox with "dynamic" javascript array

  1. #1
    Sencha User
    Join Date
    Jan 2016
    Posts
    11
    Answers
    1

    Default Answered: Build menu or comboBox with "dynamic" javascript array

    Hi,

    I want to add a comboBox or menu button to my interface which will have data in it that comes from an array. The data in the array won't always be the same so I need the button to be "dynamic". How can I achieve that ? I can't specify a model if the array changes...

    Example:
    1) Users selects a menu item and click on a send button.
    2) Depending on the value of the item the user clicked on, a javascript array is created with sometimes 2, sometimes 10 fields in it.
    3) The fields are shown in a new menu button or combobox.

    Thanks for your help !

  2. In case of menu you can remove all the items and re-add new ones:

    Code:
    Ext.application({    name: 'Fiddle',
    
    
        launch: function() {
            Ext.create('Ext.panel.Panel', {
                title: "Panel",
                width: 800,
                height: 600,
                renderTo: Ext.getBody(),
                dockedItems: [{
                    xtype: 'toolbar',
                    items: [{
                        text: "Randomize",
                        handler: function(btn) {
    						var menu = btn.nextSibling().down('menu'),
                                numberOfElements = Ext.Number.randomInt(1, 10);
                            menu.removeAll();
                            // Recreate your menu.
                            for(var i=1; i<numberOfElements; i++) {
                                menu.add({
                                    text: "Menu Item: " + i
                                })
                            };
                        },
                        scope: this
                    }, {
                        xtype: 'button',
                        text: "Dynamic Menu",
                        menu: []
                    }]
                }]
            });
        }
    });
    In case of combobox, you can remove the combobox from the parent element and create new one with new diferent store and model.

  3. #2
    Sencha User
    Join Date
    Mar 2009
    Location
    München
    Posts
    574
    Answers
    99

    Default

    In case of menu you can remove all the items and re-add new ones:

    Code:
    Ext.application({    name: 'Fiddle',
    
    
        launch: function() {
            Ext.create('Ext.panel.Panel', {
                title: "Panel",
                width: 800,
                height: 600,
                renderTo: Ext.getBody(),
                dockedItems: [{
                    xtype: 'toolbar',
                    items: [{
                        text: "Randomize",
                        handler: function(btn) {
    						var menu = btn.nextSibling().down('menu'),
                                numberOfElements = Ext.Number.randomInt(1, 10);
                            menu.removeAll();
                            // Recreate your menu.
                            for(var i=1; i<numberOfElements; i++) {
                                menu.add({
                                    text: "Menu Item: " + i
                                })
                            };
                        },
                        scope: this
                    }, {
                        xtype: 'button',
                        text: "Dynamic Menu",
                        menu: []
                    }]
                }]
            });
        }
    });
    In case of combobox, you can remove the combobox from the parent element and create new one with new diferent store and model.

Similar Threads

  1. JavaScript Array
    By dreamcaster in forum Ext 3.x: Help & Discussion
    Replies: 3
    Last Post: 13 Oct 2009, 1:23 AM
  2. javascript array in AJAX POST
    By BlueCamel in forum Ext 2.x: Help & Discussion
    Replies: 7
    Last Post: 3 Jul 2009, 5:30 AM
  3. My contrib - Javascript Bag Collection (or Bag Array)
    By fulvius in forum Community Discussion
    Replies: 2
    Last Post: 29 Jun 2008, 6:02 PM
  4. assoc array does javascript support it ?
    By Florynth in forum Community Discussion
    Replies: 4
    Last Post: 19 Sep 2007, 4:09 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •