Results 1 to 5 of 5

Thread: FormPanel, Checkbox, for loop

  1. #1
    Sencha User rothaar's Avatar
    Join Date
    Jul 2008
    Posts
    64

    Default FormPanel, Checkbox, for loop

    Heya gang. Having a little trouble with the following snippet of code:

    Code:
       var logTbl = CE('table', 'tblLoggingCats');
       logTbl.setAttribute('class', 'loggingTable');
       logTbl.setAttribute('className', 'loggingTable');
       Application.contDocBody.dom.appendChild(logTbl);
     
       for(i=0;i<logCategoryObj.modules.length;i++) {
        if (i % 3 == 0) {
         var modRow = logTbl.insertRow(logTbl.rows.length);
        }
        var modCell = modRow.insertCell(modRow.cells.length);
        modCell.setAttribute('class', 'loggingCell');
        modCell.setAttribute('className', 'loggingCell');
        var catName = new Ext.form.Checkbox({
         boxLabel: _(logCategoryObj.modules[i].name)
        });
        var catList = [];
        for(j=0;j<logCategoryObj.modules[i].categories.length;j++) {
         catList[j] = new Ext.form.Checkbox({
          boxLabel: _(logCategoryObj.modules[i].categories[j].name)
         });
        }
        new Ext.form.FormPanel({
         baseCls: 'x-plain',
         defaults: {
          border: false,
          hideLabel: true
         },
         items: [
          catName,
          catList
         ]
        }).render(Ext.get(modCell));
       }
    My logCategoryObj is an object containing (currently) 7 "modules", each of which have a "name" and a list of between 1 and 7 "categories" (each of which have both a "name" and an "enabled" boolean value).

    When I run this, my category names all render beautifully, with their associated checkboxes ('check all' logic to be added later), but none of the "catList[]" names or checkboxes show up (just whitespace where maybe one of them would fit). When I drill down with the IE Dev toolbar, I see that only the 'x-panel-body' div is being created. Does anyone see a syntax error I'm overlooking?

  2. #2
    Sencha User rothaar's Avatar
    Join Date
    Jul 2008
    Posts
    64

    Default

    This is still stumping me. I've rearranged the code a couple different ways, all with the same results mentioned above. Certainly I must be missing something elementary. Anybody see what I'm doing wrong?

  3. #3
    Sencha User rothaar's Avatar
    Join Date
    Jul 2008
    Posts
    64

    Default

    There must be something wrong with how I'm calling my catList array of checkboxes in the 'items' list for the FormPanel. If I explicitly call a single one of the checkboxes in the array...

    Code:
       var logTbl = CE('table', 'tblLoggingCats');
       logTbl.setAttribute('class', 'loggingTable');
       logTbl.setAttribute('className', 'loggingTable');
       Application.contDocBody.dom.appendChild(logTbl);
     
       for(i=0;i<logCategoryObj.modules.length;i++) {
        if (i % 3 == 0) {
         var modRow = logTbl.insertRow(logTbl.rows.length);
        }
        var modCell = modRow.insertCell(modRow.cells.length);
        modCell.setAttribute('class', 'loggingCell');
        modCell.setAttribute('className', 'loggingCell');
        var catName = new Ext.form.Checkbox({
         boxLabel: _(logCategoryObj.modules[i].name)
        });
        var catList = [];
        for(j=0;j<logCategoryObj.modules[i].categories.length;j++) {
         catList[j] = new Ext.form.Checkbox({
          boxLabel: _(logCategoryObj.modules[i].categories[j].name)
         });
        }
        new Ext.form.FormPanel({
         baseCls: 'x-plain',
         defaults: {
          border: false,
          hideLabel: true
         },
         items: [
          catName,
          catList[0]
         ]
        }).render(Ext.get(modCell));
       }
    ...like so, it renders that one item (first 'categories.name' for each 'modules'). Why can't I just call the entire array like in my first post?

  4. #4
    Sencha User Condor's Avatar
    Join Date
    Mar 2007
    Location
    The Netherlands
    Posts
    24,245

    Default

    Use:

    Code:
    items: [catName].concat(catList)

  5. #5
    Sencha User rothaar's Avatar
    Join Date
    Jul 2008
    Posts
    64

    Default

    Condor! You are, again, my hero. Thanks for the tip, and /facepalm on me for not knowing to do that myself.

Posting Permissions

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