1. #1
    Sencha Premium Member Martin1982's Avatar
    Join Date
    Aug 2011
    Location
    The Netherlands
    Posts
    109
    Vote Rating
    0
    Martin1982 is on a distinguished road

      0  

    Question Does Sencha Touch Model always have to contain an Array?

    Does Sencha Touch Model always have to contain an Array?


    It seems like in this topic http://www.sencha.com/forum/showthre...an-Array/page2 order has been restored to the universe, but what about Sencha Touch?

    I'm having the same issue now;
    An external API, which is not returning a single record as an array of the object, but just as an object, and I want to read it.
    Anyone know a good workaround for this?

  2. #2
    Sencha User
    Join Date
    Jul 2010
    Location
    Switzerland
    Posts
    78
    Vote Rating
    0
    fx-mike is on a distinguished road

      0  

    Default


    Write a custom reader and put the object inside of an array for further processing.
    You can find a code sample here: http://www.sencha.com/forum/showthre...l=1#post633893
    Last edited by fx-mike; 30 Aug 2011 at 8:52 AM. Reason: added link to code sample

  3. #3
    Sencha Premium Member Martin1982's Avatar
    Join Date
    Aug 2011
    Location
    The Netherlands
    Posts
    109
    Vote Rating
    0
    Martin1982 is on a distinguished road

      0  

    Default


    Thanks for the link, I got it working as a new reader;

    Code:
    Ext.data.JsonRecordReader = Ext.extend(Ext.data.JsonReader, {
        /**
         * Reads a JSON object and returns a ResultSet. Uses the internal getTotal and getSuccess extractors to
         * retrieve meta data from the response, and extractData to turn the JSON data into model instances.
         * @param {Object} data The raw JSON data
         * @return {Ext.data.ResultSet} A ResultSet containing model instances and meta data about the results
         */
        readRecords: function(data) {
            if (Ext.isArray(data)) {
                data = data[0];
            }
            
            if (!data.results) {
                data = {
                    'total': 1,
                    'skip': 0,
                    'limit': 20,
                    'results': [data]
                }
            }
    
            return Ext.data.JsonRecordReader.superclass.readRecords.call(this, data);
        }
    });
    
    Ext.data.ReaderMgr.registerType('jsonrecord', Ext.data.JsonRecordReader);

Thread Participants: 1

film izle

hd film izle

film sitesi

takipci kazanma sitesi

takipci kazanma sitesi

güzel olan herşey

takipci alma sitesi

komik eğlenceli videolar