1. #1
    Ext User
    Join Date
    Dec 2007
    Posts
    5
    Vote Rating
    0
    xdevice is on a distinguished road

      0  

    Default 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

  2. #2
    Sencha - Community Support Team Condor's Avatar
    Join Date
    Mar 2007
    Location
    The Netherlands
    Posts
    24,246
    Vote Rating
    97
    Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of

      0  

    Default


    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');

  3. #3
    Ext User
    Join Date
    Dec 2007
    Posts
    5
    Vote Rating
    0
    xdevice is on a distinguished road

      0  

    Default


    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:

    var list = Ext.select('DIV.rowItem');
    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.

    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

  4. #4
    Sencha - Community Support Team Condor's Avatar
    Join Date
    Mar 2007
    Location
    The Netherlands
    Posts
    24,246
    Vote Rating
    97
    Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of

      0  

    Default


    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.

  5. #5
    Ext User
    Join Date
    Dec 2007
    Posts
    5
    Vote Rating
    0
    xdevice is on a distinguished road

      0  

    Default


    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

  6. #6
    Sencha User
    Join Date
    Mar 2007
    Posts
    7,854
    Vote Rating
    4
    tryanDLS is on a distinguished road

      0  

    Default


    You could also maintain them as a MixedCollection, which supports things like add and remove and find.

Thread Participants: 2