We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 10378
    • 375 Posts
    Hello - and here I am with another small problem:

    Why doesn't this ExtJS modx-combo display data?
    The combo renders with the correct number of items - but all items are empty (only small selectable empty lines).
    If you have a look at the console log - the JsonStore seems perfectly filled!

    The code part below is from a toolbar of a MODx.grid and will be used as a filter for the grid.

    ...
            ,{
                xtype: 'modx-combo'
                ,emptyText: _('goodnews.subscribers_user_group')+'...'
                ,width: 200
                ,displayField: 'name'
                ,valueField: 'id'
                ,store: new Ext.data.JsonStore({
                    url: GoodNews.config.connectorUrl
                    ,baseParams: {
                        action : 'mgr/settings/getMemberGroupList'
                    }
                    ,fields: ['id','name']
                    ,root: 'results'
    
                    // debug
                    ,listeners: {
                        'load': {
                            fn: function(obj, options, response, e){
                                console.info(arguments);
                            }
                        }
                    }
     
                })
                ,listeners: {
                    'select': {fn:this.filterByUserGroup,scope:this}
                }
            }
    ...
    


    And here is the processor code which reads a comma separated string of values from the system settings.
    (e.g. "groupA,groupB,groupC,groupD")

    The processor returns this json string:

    {"total":"4","results":[{"groupA":"groupA"},{"groupB":"groupB"},{"groupC":"groupC"},{"groupD":"groupD"}]}
    


    <?php
    // read defined mailing member group names from system setting (comma separated list of values)
    $groups = $modx->getOption('goodnews.mailing_member_groups');
    $grouplist = explode(",", $groups);
    
    $list = array();
    foreach ($grouplist as $group) {
        $list[] = array($group => $group);
    }
    
    $modx->log(xPDO::LOG_LEVEL_INFO, 'Groups sent back to JS: '. $this->outputArray($list));
    
    return $this->outputArray($list);
    


    This whole ExtJS thing slowly drives me crazy...

    This question has been answered by gadgetto. See the first response.

      Freelancer @bitego http://www.bitego.com
      ---
      GoodNews - one of the most advanced and integrated Group Mailer premium add-ons for MODX Revolution!
      More infos here: http://www.bitego.com/extras/goodnews/
    • discuss.answer
      • 10378
      • 375 Posts
      OK - could again solve this without help (tooks 4 days to find solution)!

      The retuned Json string has to be:
      (Note: in this special case the id and name field have the same values as I build the array from a comma separated list of single values)

      {"total":"4","results":[{"id":"groupA","name":"groupA"},{"id":"groupB","name":"groupB"},{"id":"groupC","name":"groupC"},{"id":"groupD","name":"groupD"}]}
      


      Why isn't there a hint in the documentation how the returned Json string has to be formatted?


      This is the processor code with the fix (in line 10 are the changes)

      <?php
      // read defined mailing member group names from system setting
      $groups = $modx->getOption('goodnews.mailing_member_groups');
      $grouplist = explode(",", $groups);
      
      $modx->log(modX::LOG_LEVEL_INFO, 'Groups from settings: ' . $modx->toJson($grouplist));
      
      $list = array();
      foreach ($grouplist as $group) {
          $list[] = array('id' => $group, 'name' => $group);
      }
      
      $modx->log(xPDO::LOG_LEVEL_INFO, 'Sent back to JS: '. $this->outputArray($list));
      
      return $this->outputArray($list);
      
      [ed. note: gadgetto last edited this post 13 years, 10 months ago.]
        Freelancer @bitego http://www.bitego.com
        ---
        GoodNews - one of the most advanced and integrated Group Mailer premium add-ons for MODX Revolution!
        More infos here: http://www.bitego.com/extras/goodnews/