Gelmiş geçmiş en büyük porno sitemiz olan 2pe de her zaman en kaliteli pornoları sunmayı hedefledik. Diğer video sitemiz olan vuam da ise hd porno ağırlıklı çalışmalara başladık.

  1. #1
    Sencha User
    Join Date
    Jun 2011
    Posts
    4
    Vote Rating
    0
    jvankessel is on a distinguished road

      0  

    Question Ext.data.JsonReader root property problem

    Ext.data.JsonReader root property problem


    Hi,

    I'm having a lot of trouble getting a data store working in my grid. I have a PHP script which is generating JSON output as shown below. When I set the root property in my reader to "data" nothing is shown in my grid. When I encode the customerData directly to JSON without specifying a root property it all works great. But I need the extra properties in order to get my paging on.

    I've already tried everything the last few days but I'm pretty stuck right now. What I'm doing wrong here?

    As I'm new to extjs it could also be i'm doing something really stupid here

    Any help would be very appreciated!

    Regards Jasper

    PHP Code:
    $o = array(
         
    "data"       => $customerData,
         
    "success"    => true,
         
    "totalCount" => sizeof($customerData)
    );
     
    echo 
    json_encode($o); 
    Which outputs:

    {"data":[{"customer_id":"213"},{"customer_id":"196"}],"success":true,"totalCount":2}

    This is the sample code:
    Code:
        var proxy = new Ext.data.HttpProxy({
          url:'adapters/data.customers.php'
        });
        
        var reader = new Ext.data.JsonReader({
          totalProperty: 'totalCount',
          successProperty: 'success',
          root: 'data'
        }, [
            {name: 'customer_id', type: 'int', mapping:'customer_id'}
        ]);
        
        var ds = new Ext.data.Store({
          autoLoad: true,
          proxy: proxy,
          reader: reader,
          remoteSort: true,
          fields: [
            {name: 'customer_id', type: 'int', mapping:'customer_id'}
        ]
        });    
    
        // create the Grid
        var grid = Ext.define('customers', {
            extend:'Ext.grid.Panel',
            alias: 'widget.customers',
            store: ds,
            stateful: true,
            stateId: 'stateGrid',
            columns: [
                {
                    text     : 'ID',
                    flex     : 1,
                    sortable : true,
                    dataIndex: 'customer_id'
                }
            ],
            layout: 'fit',
            title: 'Customers',
            viewConfig: {
                stripeRows: true
            }
        });

  2. #2
    Sencha User Seana's Avatar
    Join Date
    Jun 2010
    Posts
    82
    Vote Rating
    0
    Seana is on a distinguished road

      0  

    Default


    I'm shooting from the hip here, I've been off in c# land for the last few months, but as I recall the reader doesn't need the fields... try replacing

    Code:
    var reader = new Ext.data.JsonReader({
          totalProperty: 'totalCount',
          successProperty: 'success',
          root: 'data'
        }, [
            {name: 'customer_id', type: 'int', mapping:'customer_id'}
        ]);
    with

    Code:
    var reader = new Ext.data.JsonReader({
          totalProperty: 'totalCount',
          successProperty: 'success',
          root: 'data'
        });
    Sean

  3. #3
    Sencha User
    Join Date
    Jun 2011
    Posts
    4
    Vote Rating
    0
    jvankessel is on a distinguished road

      0  

    Default


    Thanks for your reply.

    Unfortunately it gives the same result.

    If I output the JSON like this:

    [{"customer_id":"213"},{"customer_id":"196"}]

    It all works, even when the root parameter still being set to 'data'.

    Any ideas?

  4. #4
    Ext JS Premium Member
    Join Date
    May 2011
    Posts
    13
    Vote Rating
    0
    rgendler is on a distinguished road

      0  

    Default


    If I am not mistaken you are using ExtJS 4
    Then how about simply using Rest proxy. I believe HttpProxy is something used in ExtJS 3 and is deprecated in 4.
    Something like:

    var proxy = new Ext.data.proxy.Rest({
    url:'adapters/data.customers.php'
    });

    Also Ext.data.JsonReader is from version 3 too. You should use Ext.data.reader.Json or just Ext.data.reader.Reader
    and specifying type as 'json'

  5. #5
    Sencha User
    Join Date
    Jun 2011
    Posts
    4
    Vote Rating
    0
    jvankessel is on a distinguished road

      0  

    Default


    Tried your suggestions but still no luck.

    Could there be something wrong with my JSON string?

    This doesn't work (with root parameter set to 'data'):
    {"data":[{"customer_id":"213"},{"customer_id":"196"}],"success":true,"totalCount":2}

    This works (also with root parameter set to 'data' or no root set at all):
    [{"customer_id":"213"},{"customer_id":"196"}]

    It seems like the reader is ignoring the root parameter or something.

  6. #6
    Ext JS Premium Member
    Join Date
    May 2011
    Posts
    13
    Vote Rating
    0
    rgendler is on a distinguished road

      0  

    Default


    Ok

    Could it be the absence of the double quotes around string true and the number 2 in "success" and "totalCount" respectively.

  7. #7
    Sencha User
    Join Date
    Jun 2011
    Posts
    4
    Vote Rating
    0
    jvankessel is on a distinguished road

      0  

    Default


    This morning I finally got it working! Also thanks to your tips about the deprecated functions I looked for a more Extjs 4 approach.

    Instead of creating the proxy and reader objects separately I specified the proxy and reader parameters directly in the data store object like this:

    Code:
        
    var ds = new Ext.data.Store({
          proxy: {
              type: 'ajax',
              url : 'adapters/data.customers.php',
              reader: {
                  type: 'json',
                  root: 'items',
                  totalProperty: 'numrows'
              }
          },
          etc...
    Now it all works perfect. Thanks for your help!

Thread Participants: 2

Tags for this Thread