1. #1
    Sencha User
    Join Date
    Apr 2012
    Posts
    12
    Vote Rating
    0
    omargarcianet is on a distinguished road

      0  

    Default Unanswered: Issue loading data into a store

    Unanswered: Issue loading data into a store


    Hello everyone,

    I'm trying to load some data into store and I'm afraid that I'm not understanding very well how it works.

    Here's my model/store:

    Code:
    Ext.define('tourAsturias.model.LoginModel', {
        extend: 'Ext.data.Model',
    
    
        config: {
            
            idProperty	: 'id',
            
            fields: [
            {
                name: 'id',
                type:'integer'
            },
            
            {
                name: 'login',     
                type: 'string'
            },
           
            {
                name: 'clave', 
                type: 'string'
            },
               {
                name: 'tipo', 
                type: 'string'
            },
               {
                name: 'descripcion', 
                type: 'string'
            },
            {
                name: 'email',    
                type: 'string'
            },
            
            ],
            validations: [
            {
                type: 'presence', 
                field: 'login',
                message: 'Debe introducir un nombre de usuario'
            },
            {
                type: 'presence',
                field: 'clave',
                message: 'Debe introducir una contraseña'
            },
           
              
            ],
            
            
            proxy		: {
                type: 'ajax',
                api: {
                    
                    read    : 'php/login/login.php'
                   
                },
                actionMethods: {
                   
                    read    : 'GET'
                    
                },
                
               //callbackKey: 'callback',
            
              reader: {
                    type: 'json'
                   
                    
                                
                    //idProperty: 'id',
                    //root: 'user'
                   // rootProperty: '0'
                   //successProperty: 'success'
              }
    
    
                },
                writer: {
                    type: 'json',
                    writeAllFields: true,
                    root: 'login',
                    encode: true
                }
            
    
    
        },
        
        /**
         *@showValidationMessages 
         *
         *@params {errors} objeto que contienen los errores que se producen en la validación
         *
         *Muestra los mensajes de error en un pop-up en caso de que los hubiera
         *
         */
        
        showValidationMessages: function(errors) {
          
            
            //Mostrar errores
            console.log('Is User valid?', errors.isValid()); // returns 'false' si hay errores de validación
            console.log('All Errors:', errors.items);// returns con todos los errores encontrados en la instacia del modelo
            
            var msg='';
            if (!errors.isValid()) {
             
                errors.each(function (errors) {
                    msg += errors.getMessage() + '<br/>';
                });
                Ext.Msg.alert('ERROR', msg);
            }
            
     
        }
        
        
        
    });
    ***********************************************
    Ext.define('tourAsturias.store.LoginStore', {
        extend  : 'Ext.data.Store',
       
        
        config: {
            model   : 'tourAsturias.model.LoginModel',
            storeId: 'loginStore',
         
            autoLoad: true,
            autoSync: true
            //autoDestroy:true
        }
        
       
        
        
    });
    And this is the way in which I'm trying to load the store:


    Code:
     
            var loginStore = Ext.create('tourAsturias.store.LoginStore');
            
            loginStore.load({
                
                 
                params:{
                    
                    login: form['login'],
                    clave: form['clave']
                    
                },
                
                success: function() {
                    
                    console.log('Success');
                   
                    Ext.Msg.alert('Success', 'Success');
            
                },
                failure: function() {
                    //do something if the load failed
                    console.log('Failure');
                    Ext.Msg.alert('Failure', 'Failure');
                },
                
               callback : function(records, operation, success) {
                    console.log('JSON returned');
                    console.log(records);
                    console.log(operation);
                    console.log(success);
    
    
                },
                scope: this
               
             
                
            });
    I send two params to my server and I'm getting the following JSON response:

    Code:
    {"id":"1","login":"admin","clave":"admin","tipo":"1","descripcion":"Administrador del sistema","nombre":"Administrador General","email":"estudio3@impact5.es"}
    My problem is that it always calls my callback function and I would like to know how could I do to invoke success or failure in order to do different things in each case.

    Thanks in advance for your help.

  2. #2
    Sencha User
    Join Date
    Jan 2012
    Location
    London, UK
    Posts
    498
    Answers
    25
    Vote Rating
    51
    shepsii has a spectacular aura about shepsii has a spectacular aura about shepsii has a spectacular aura about

      1  

    Default


    At the moment it looks like your response from your server is returning a single json object. It needs to return an array of objects, even if you only want to put one record into the store.

  3. #3
    Sencha User
    Join Date
    Apr 2012
    Posts
    12
    Vote Rating
    0
    omargarcianet is on a distinguished road

      0  

    Default


    First of all, thanks for your reply. Anyway when I return an array I'm getting the same issue.

    Here is my reader config in my proxy:

    Code:
     reader: {
                    type: 'json',
                    rootProperty: 'user',
                   successProperty: 'success'
              }
    This is how I return an array of JSON objects in PHP
    Code:
      echo json_encode(array(
               'success'=>true, 
               'user'=>$data
            ));
    Response from the server:
    Code:
    {"success":true,"user":[{"id":"1","login":"admin","clave":"admin","tipo":"1","descripcion":"Administrador del sistema","nombre":"Administrador General","email":"estudio3@impact5.es"}]}
    What I wanted to know is why it is always called my callback function and what I should write in my code to change it.

    Thanks in advance.

  4. #4
    Sencha - Senior Forum Manager mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    36,791
    Answers
    3465
    Vote Rating
    833
    mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute

      0  

    Default


    Quote Originally Posted by omargarcianet View Post
    What I wanted to know is why it is always called my callback function and what I should write in my code to change it.
    The callback function will always be called, the success function will only be called when the server response status is 200 (some others also) and failure function will only be called when the server response status is bad like 404 or 500 or the such.
    Mitchell Simoens @SenchaMitch
    Sencha Inc, Senior Forum Manager
    ________________
    Check out my GitHub, lots of nice things for Ext JS 4 and Sencha Touch 2
    https://github.com/mitchellsimoens

    Think my support is good? Get more personalized support via a support subscription. https://www.sencha.com/store/

    Need more help with your app? Hire Sencha Services services@sencha.com

    Want to learn Sencha Touch 2? Check out Sencha Touch in Action that is in print!

    When posting code, please use BBCode's CODE tags.

  5. #5
    Sencha User
    Join Date
    Apr 2012
    Posts
    12
    Vote Rating
    0
    omargarcianet is on a distinguished road

      0  

    Default


    Thanks for your answer Mitchell.

    I can´t understand why if my server response status is 200 I never see my success function invoked. Could you please tell me what I'm doing wrong in my code?

    It's been hard getting started. I hardly ever find some good examples and there is not yet a large community of experienced developers with sencha.

    Code:
     loginStore.load({
                
                 
                params:{
                    
                    login: form['login'],
                    clave: form['clave']
                    
                },
                scope: this,
                
                success: function() {
                    
                    console.log('Success');
                   
                    Ext.Msg.alert('Success', 'Success');
            
                },
                failure: function() {
                    //do something if the load failed
                    console.log('Failure');
                    Ext.Msg.alert('Failure', 'Failure');
                },
                
               callback : function(records, operation, success) {
                    console.log('JSON returned');
                    console.log(records);
                    console.log(operation);
                    console.log(success);
                   
                    Ext.Msg.alert('Yeahh', 'Yeahhh');
                }
    Code:
    • Request URL: http://localhost/senchaApp/php/login/login.php?_dc=1341601754934
    • Request Method: POST
    • Status Code: 200 OK
    • Request Headersview source
      • Accept: */*
      • Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.3
      • Accept-Encoding: gzip,deflate,sdch
      • Accept-Language: es-ES,es;q=0.8
      • Connection: keep-alive
      • Content-Length: 47
      • Content-Type: application/x-www-form-urlencoded; charset=UTF-8
      • Host: localhost
      • Origin: http://localhost
      • Referer: http://localhost/senchaApp/
      • User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_4) AppleWebKit/536.11 (KHTML, like Gecko) Chrome/20.0.1132.47 Safari/536.11
      • X-Requested-With: XMLHttpRequest
    • Query String Parametersview URL encoded
      • _dc: 1341601754934
    • Form Dataview URL encoded
      • login: admin
      • clave: admin
      • page: 1
      • start: 0
      • limit: 25
    • Response Headersview source
      • Connection: Keep-Alive
      • Content-Length: 184
      • Content-Type: application/x-json
      • Date: Fri, 06 Jul 2012 19:09:14 GMT
      • Keep-Alive: timeout=5, max=100
      • Server: Apache/2.2.14 (Unix) DAV/2 mod_ssl/2.2.14 OpenSSL/0.9.8l PHP/5.3.1 mod_perl/2.0.4 Perl/v5.10.1
      • X-Powered-By: PHP/5.3.1

  6. #6
    Sencha - Senior Forum Manager mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    36,791
    Answers
    3465
    Vote Rating
    833
    mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute

      0  

    Default


    This example on try.sencha.com loads a JSON file remotely that may help you:

    http://try.sencha.com/touch/2.0.0/examples/list/
    Mitchell Simoens @SenchaMitch
    Sencha Inc, Senior Forum Manager
    ________________
    Check out my GitHub, lots of nice things for Ext JS 4 and Sencha Touch 2
    https://github.com/mitchellsimoens

    Think my support is good? Get more personalized support via a support subscription. https://www.sencha.com/store/

    Need more help with your app? Hire Sencha Services services@sencha.com

    Want to learn Sencha Touch 2? Check out Sencha Touch in Action that is in print!

    When posting code, please use BBCode's CODE tags.

  7. #7
    Sencha User
    Join Date
    Apr 2012
    Posts
    12
    Vote Rating
    0
    omargarcianet is on a distinguished road

      0  

    Default


    I appreciate your help but it is not what I was looking for because in this example you gave me the information loaded into the store comes from a local file called contacts.json wich contains a list of names. In my code I need to load a JSON object that I get as a response from my server and do different things wether the operation is succeeded or failed. That's why I don´t understand well why my success function is never invoked.

    Thanks anyway.

Thread Participants: 2

Tags for this Thread

Turkiyenin en sevilen filmlerinin yer aldigi xnxx internet sitemiz olan ve porn sex tarzi bir site olan mobil porno izle sitemiz gercekten dillere destan bir durumda herkesin sevdigi bir site olarak tarihe gececege benziyor. Sitenin en belirgin ozelliklerinden birisi de Turkiyede gercekten kaliteli ve muntazam, duzenli porno izle siteleri olmamasidir. Bu yuzden iste. Ayrica en net goruntu kalitesine sahip adresinde yayinlanmaktadir. Mesela diğer sitelerimizden bahsedecek olursak, en iyi hd porno video arşivine sahip bir siteyiz. "The Best anal porn videos and slut anus, big asses movies set..." hd porno faketaxi