Results 1 to 10 of 10

Thread: Problem with store , dont get the record

  1. #1

    Default Problem with store , dont get the record

    Hello all ,

    I ve been trying for like 24 hours now to populate a form from a Datastore , using either the Json reader .

    Now it looks that its all okay , but when trying to access the record no matter wht i always get back undefined , also in firebug in the DOM i don see the json data in the items i just see a blank [].
    i know its asynchrounos and i use store.on('load',function(){});
    and an alert tells me it gets there.

    however when trying to access something like
    store.getAt(0).id
    i get back undefined.

    Here the code ,

    Code:
    
    
    function
    EditProvider(v) {
    var EditProviderID = v;
    Ext
    .Msg.confirm('Confirm Editing Provider','please confirm that you would like to edit this provider',function deletehandler(e) {
    var dsCurrentProduct
    =new Ext.data.Store({
    proxy
    :new Ext.data.HttpProxy({
    url
    :'get_providers.php?ProvdedorID='+EditProviderID,
    method
    :'post'
    }),
    reader
    :new Ext.data.JsonReader({
    //root: 'records',
    // totalProperty: 'totalCount',
    //id: 'id'
    },[{
    name
    :'id'
    },{
    name
    :'company_name'
    },{
    name
    :'company_email'
    },{
    name
    :'company_contact'
    },{
    name
    :'active'
    },{
    name
    :'countryID'
    },{
    name
    :'familyID'
    },{
    name
    :'added'
    }])
    });
    dsCurrentProduct
    .on("load",function(){
    alert
    ('loading');//ok
    var firstRec = dsCurrentProduct.getAt(0);//undefined
    alert
    ("Total recs: "+ dsCurrentProduct.getTotalCount()+
    "\nFirst record id: "+
    firstRec
    .id +
    ", name: \""+
    firstRec
    .get("company_name")+
    "\"");
    });
    dsCurrentProduct.load();

    the other code to obtain the same result was
    Code:
    
    
    var provider_data = new Ext.data.Store({
    proxy: new Ext.data.HttpProxy({url: 'get_providers.php?ProvdedorID='+EditProviderID}),
    reader: new Ext.data.JsonReader({},[ 'id', 'company_name', 'company_email', 'company_contact', 'active','countryID','familyID','added']),
    remoteSort: false }); var provider_data = new Ext.data.JsonStore({
    url: 'get_providers.php?ProvdedorID='+EditProviderID,
    fields: [ {
    name: 'id'
    },{
    name: 'company_name'
    },{
    name: 'company_email'
    }, {
    name: 'company_contact'
    },{
    name: 'active'
    },{
    name: 'countryID'
    },{
    name: 'familyID'
    },{
    name: 'added'
    }
    ]
    }); //alert(provider_data.getById(company_name).data); provider_data.on("load", function() {
    //wait until whole dataStore is loaded, and THEN do everything with provider_data:
    //
    alert('im here');
    //provider_data.each(function(r){alert(r.data['company_name']); });
    //console.log(provider_data);
    alert(provider_data.jsonData );
    });
    provider_data.load();
    //alert(provider_data.getById('company_name') );

    I would apreciate any insight on this matter.
    The result is that i want to edit data and prepolutate the form with this obtained record

    Thanks in advance,
    Laurentius

  2. #2

    Default

    i think you should make sure that the data is come from server.. then after that, you may see that passed data in firebug...

  3. #3

    Default thanks

    Thanks for that , im sure that the data has come from the server ,
    i look in firebug in "red" and i see the json output generated,
    but for some reason it dont read it.
    hence i dont know why it dont read it and how i could debug this.

  4. #4

    Default

    thinking...

  5. #5

    Default TESTED

    Hi , thanks again , but it doesnt get fired , i get the alert loading but thats it

    Code:
    dsCurrentProduct.on("load",function(){
    Code:
    
    
    alert
    ('loading');// THIS ONE WORKS
    if(dsCurrentProduct.getCount()>0)// IT DOESNT FIRE {
    alert
    ("i got the data wa haha~~");
    var firstRec = dsCurrentProduct.getAt(0);
    alert
    ("Total recs: "+ dsCurrentProduct.getTotalCount()+
    "\nFirst record id: "+
    firstRec
    .id +
    ", name: \""+
    firstRec
    .get("company_name")+
    "\"");
    }
    });
    dsCurrentProduct.load();


  6. #6

    Default

    because i do the same way as you to get the data from the server, and the load function is called when the client finshed load the data , if you can not get the data here, that may means the server data is not transfer to the client.....

  7. #7

    Default

    when i look in firebug at the phpscript and answer i get json back

    Code:
    {"0":"36","id":"36","1":"content","company_name":"content","2":"[email protected]","company_email":"[email protected]","3":"534534","company_contact":"534534","4":"1","active":"1","5":"29","countryID":"29","6":"2","familyID":"2","7":"2009-06-24 10:02:43","added":"2009-06-24 10:02:43"}

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

    Default

    A JsonReader can't process that, because it has no root (an element that holds an array of records).

    It should output:
    Code:
    [{"id":"36","company_name":"content","company_email":"[email protected]","company_contact":"534534","active":"1","countryID":"29","familyID":"2","added":"2009-06-24 10:02:43"}]
    Note the extra []-brackets.

    ps. I also removed the strange data duplication in your JSON.

  9. #9

    Default

    when i read the data you got.. found something strange. and as the Condor says. it maybe the problem,

  10. #10

    Default thanks

    Indeed the [] (brackets) did it, thanks very much and this i wont miss the next time!

    Thanks to both of you for your time.

    Luck

Posting Permissions

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