PDA

View Full Version : toolbar



dyth
18 Mar 2011, 1:16 AM
Hi All,

I would like to generic the item for the toolbar the following is the code I've and working



function initMenu(){

var tbr = new Ext.Toolbar({
renderTo: "divToolbar",
items: [{
'text:"Home", iconCls:"ico_house"'
}]
});
tbr.render('divToolbar');
}


Since I plan to make this way, to put variable and let load according



function initMenu(obj){

var displayMenuItem = ""
if(obj=="partA"){

}else{
displayMenuItem = "text:'Home', iconCls:'home_ico'";
}

var tbr = new Ext.Toolbar({
renderTo: "divToolbar",
items: [{
displayMenuItem
}]
});
tbr.render('divToolbar');
}


From the code above I still unable to create the menu item by assign into variable "displayMenuItem"

The following is the testing I have done, either the "displayMenuItem" is null / empty / got data will get this error "invalid object initializer"

P/s: all the error I get from firebug - Mozilla firebox

I wanted to make the toolbar item more generic, as if there some data I need can put in the variable and let the code load. If someone have a better idea / solution please let me know

Thank You

- David

mcadirci
18 Mar 2011, 1:30 AM
Try:

function initMenu(obj){

var displayMenuItem = {};
if(obj=="partA"){

}else{
displayMenuItem = { "text":"Home", "iconCls":"home_ico" };
}

var tbr = new Ext.Toolbar({
renderTo: "divToolbar",
items: [displayMenuItem ]
});
tbr.render('divToolbar');
}

dyth
18 Mar 2011, 2:05 AM
thank you is work now! :D:D

dyth
19 Mar 2011, 12:41 AM
Hi,

I got another question




function initMenu(obj){

var displayMenuItem = {};
if(obj=="partA"){

}else{
displayMenuItem = { "text":"Home", "iconCls":"home_ico" };
}

var tbr = new Ext.Toolbar({
renderTo: "divToolbar",
items: [displayMenuItem ]
});
tbr.render('divToolbar');
}
As the code is working but when I try add another item it will hit the error

I try add the "-" or another menu but fail
displayMenuItem = { "text":"Home", "iconCls":"home_ico"},"-",{"text":"Testing"};

Hope some one can correct my mistake

Thank You

--------------------------------------------------

I've found the solution need put the [] in the displayMenuItem

Thank You