1. #1
    Sencha User Phunky's Avatar
    Join Date
    Jun 2007
    Location
    West Yorkshire
    Posts
    341
    Vote Rating
    0
    Phunky is on a distinguished road

      0  

    Default [HELP] Using .each() to create Ext.menu.Menu from DataStore

    [HELP] Using .each() to create Ext.menu.Menu from DataStore


    Hi guys, im getting a little confused attempting to make a Ext.menu.Menu with data from a DataStore.

    How do i go about looping through the DataStore data to add it to the menu? I assume i should be using Ext.each() but im a little confused as how to go about it ?

  2. #2
    Sencha User Phunky's Avatar
    Join Date
    Jun 2007
    Location
    West Yorkshire
    Posts
    341
    Vote Rating
    0
    Phunky is on a distinguished road

      0  

    Default


    Im guessing something like this is what im after

    Code:
    Ext.each(ds.Status['WebRoles'].data.items, function(item, index, allItems){console.log(item)})

  3. #3
    Sencha - Ext JS Dev Team evant's Avatar
    Join Date
    Apr 2007
    Location
    Sydney, Australia
    Posts
    17,050
    Vote Rating
    657
    evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute

      0  

    Default


    Store has an each method, you can just do:

    Code:
    ds.each(function(record)
    {
       //etc
    }, scope);

  4. #4
    Sencha User Phunky's Avatar
    Join Date
    Jun 2007
    Location
    West Yorkshire
    Posts
    341
    Vote Rating
    0
    Phunky is on a distinguished road

      0  

    Default


    Code:
    Ext.Panel({
    	title:'Test Menu Item',
    	html: 'Testing the BBar Menu',
    	bbar:[{
    		menu: Ext.each(ds.Status['WebRoles'].data.items, buildStatusMenu),
    		text:'Website Role', 
    	}]
    })
    
    
    function buildStatusMenu(item, index, allItems){
    	new Ext.menu.Item({text:item.data.printable_name});
    }
    That wont work will it? Do i need to create the menu first or just add to it?!

  5. #5
    Sencha - Ext JS Dev Team evant's Avatar
    Join Date
    Apr 2007
    Location
    Sydney, Australia
    Posts
    17,050
    Vote Rating
    657
    evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute

      0  

    Default


    The menu requires either a menu object, or a config object for a menu. I don't think you can just pass an array of menu items (short answer, no).

    Code:
    var menu = new Ext.menu.Menu();
    ds.each(function(record)
    {
       menu.add(doSomethingWithRecord);
    }
    );
    
    bbar: menu...

  6. #6
    Sencha User Phunky's Avatar
    Join Date
    Jun 2007
    Location
    West Yorkshire
    Posts
    341
    Vote Rating
    0
    Phunky is on a distinguished road

      0  

    Default


    Yeah, i thought it might have to been done that way - will have to fiddle with it a bit then as i was having other problems with my app when creating the menu outside of the tabPanel creation.

Thread Participants: 1