-
28 Dec 2007 6:31 PM #1
How to iterate dynamic combo boxes
How to iterate dynamic combo boxes
Hi,
I have dynamic combo boxes in my screen. So with clicking of "+" button, users can add more combo boxes and by clicking "-" users can a delete combo box.
I am looking at way to iterate through this these combo boxes. How can I access these combo boxes as arrays.
Here is the code for creating new combo box.
function addNewCombo(type) {
cBox = new Ext.Element(document.createElement('div'));
cBox.id = (type+'_'+rowCt);
cBox.value = ('selections');
cBox.addClass("rowItem");
new Ext.form.ComboBox({
store: myStore,
id:type+rowCt,
valueField: 'userId',
displayField:'name',
value:val,
typeAhead: true,
mode: 'local',
triggerAction: 'all',
emptyText:'Select',
selectOnFocus:true,
renderTo:cBox,
name:type,
forceSelection:true
});
return cBox;
}
I hope I was able to explain my scenario. If you need more info, please let me know.
Any help is much appreciated.
Regards,
Rana Biswas
-
29 Dec 2007 2:12 AM #2Sencha - Community Support Team
- Join Date
- Mar 2007
- Location
- The Netherlands
- Posts
- 24,251
- Vote Rating
- 40
You are creating the comboboxes, why not keep a list yourself?
You can also use Ext.getCmp(id), but you'll need to know the id of the combobox.
To get a list of the DIVs surrounding the comboboxes you can use:
Code:var list = Ext.select('DIV.rowItem');
-
29 Dec 2007 12:39 PM #3
Hi Condor,
Thanks for your reply.
Yes, I can maintain a separate array, and thats my last option if I am not able to figure out a way to iterate through the elements itself. Since users can also delete any of the combo box, maintaining such an array can be bit messy, but yes, it can be done.
Excuse my ignorance, but I quite don't understand the piece of code you have given:
I tried to search what exactly Ext.select do and could not find. I tried to excute above statement and it returns [Object Object] and I really donot understand, what does it mean.var list = Ext.select('DIV.rowItem');
And when I do 'Div.rowItem', which DIV does it points to?
I am not very good at JavaScript and Extjs ... so all these newbie questions.
Your help would be greatly appreciated.
Regards,
Rana Biswas
-
29 Dec 2007 1:45 PM #4Sencha - Community Support Team
- Join Date
- Mar 2007
- Location
- The Netherlands
- Posts
- 24,251
- Vote Rating
- 40
Ext.select described in the API docs.
Basically it returns a CompositeElement (or CompositeElementLite) containing every element that matches the selector.
The selector can be a CSS selector (like the one I mentioned) or a basic XPath expression.
-
31 Dec 2007 3:23 PM #5
Thanks buddy... I finally made it work with combination of CSS Selector and XPath expression.
But its tightly coupled with current structure and if there is a change in GUI this code would break.
It seems to me, traversing the dom structure may not be a good solution, but right now can't think of anything else either.
~RB
-
1 Jan 2008 11:19 AM #6
You could also maintain them as a MixedCollection, which supports things like add and remove and find.
Tim Ryan
Read BEFORE posting a question / BEFORE posting a Bug
Use Google to Search - API / Forum
API Doc (4.x | 3.x | 2.x | 1.x) / FAQ / 1.x->2.x Migration Guide / 2.x->3.x Migration Guide


Reply With Quote