Results 1 to 4 of 4

Thread: PHP json_encode() Data Types, Quotes

  1. #1
    Ext User
    Join Date
    May 2007
    Posts
    11
    Vote Rating
    0
      0  

    Question PHP json_encode() Data Types, Quotes

    I'm programming a dynamic Grid. I use PHP's json_enode() to pass the ColumnModel options. Now, I would also like to pass a renderer. My definition in PHP looks something along the lines of:

    PHP Code:
    $colModel = array(
        array(
            
    'id' => 'icon',
            
    'header' => 'Icon',
            
    'width' => 40,
            
    'dataIndex' => 'icon',
            
    'renderer' => renderIcon// where renderIcon would be the rendering function
        
    ),
        array(
            
    'id' => 'nr',
            
    'header' => 'Nr',
            
    'dataIndex' => 'nr',
            
    'width' => 200,
        ),

        ...

    );

    json_encode$colModel ); 
    On the client side I get the data from PHP with a Ext.data.Connection. This gets passed to the grid's ColumnModel:

    PHP Code:
    ...

    var 
    cm Ext.decoderesponse.responseText );

    var 
    colModel = new Ext.grid.ColumnModel(cm); 
    My problem is, that PHP's json_encode() converts the value of "renderer" to a string:
    Code:
    ...
    {"id":"icon","header":"Icon","width":40,"dataIndex":"icon","renderer":"renderIcon"}
    ...
    In the column definition, however, it needs to appear WITHOUT quotes. Does anyone have an idea how this can be done?

    Thanks!!

  2. #2
    Ext User
    Join Date
    Apr 2007
    Posts
    9
    Vote Rating
    0
      0  

    Default

    Try this:

    Code:
    $json_encoded_colModel = str_replace ('"renderIcon"', 'renderIcon', json_encode( $colModel ));

  3. #3
    Ext User
    Join Date
    May 2007
    Posts
    11
    Vote Rating
    0
      0  

    Default

    I got that far too... but that can't really be the point?! Isn't there a better way to do this?

  4. #4
    Sencha User
    Join Date
    Oct 2010
    Posts
    1
    Vote Rating
    0
      0  

    Default Esto puede ser util.

    $json_encode1 = str_replace ('"[', '', json_encode($this->list));
    $json_encode = str_replace (']"', '', $json_encode1);



    $combo['combo']['renderer'] = '[function(){}]';

Posting Permissions

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