1. #1
    Sencha User dobie_'s Avatar
    Join Date
    Sep 2011
    Location
    Seattle, WA
    Posts
    47
    Vote Rating
    0
    dobie_ is on a distinguished road

      0  

    Default Run function on rawData before JSON reader parses it

    Run function on rawData before JSON reader parses it


    Hello,
    I have a DataView set up like this (BrowsePage extends Ext.DataView):
    Code:
    Ext.create('my.app.BrowsePage', {
          id: 'searchResults',
          itemTpl: '<h1>hi!</h1>',
          store: {
            autoLoad: true,
            fields: ['applications', 'query'],
            proxy: {
              type: 'ajax',
              url: Settings.searchUrl,        
              reader: {
                type: 'json',
                root: 'MyApp::Search',         
                totalProperty: 'matchcount'     
              }
            }
          }
    });
    But Settings.searchUrl contains invalid JSON (and this will eventually be on a foreign server so I can't control that data). I need to run my custom Data.stripChars() function on the string before the JSON reader tries to parse it. Does anyone know of a way to do this while still defining my ajax proxy within the Store like this?

  2. #2
    Sencha User dobie_'s Avatar
    Join Date
    Sep 2011
    Location
    Seattle, WA
    Posts
    47
    Vote Rating
    0
    dobie_ is on a distinguished road

      0  

    Default


    Well if anyone is interested, you can override getResponseData like this, then use 'myjson' as the reader type instead of json. It works for now --

    Code:
    Ext.define('Ext.data.reader.MyJson', {
      extend: 'Ext.data.reader.Json',
      alias: 'reader.myjson',
      //inherit docs
    
      // warning: this regex sucks!
      cleanForJSON: function(str) {
        return str.replace(/[^a-z 0-9\{\}\[\]\/\\\!<>:"'\.\$\-_,]+/gi,'');
      },
    
    
      getResponseData: function(response) {
        try { 
          var data = Ext.decode(this.cleanForJSON(response.responseText));
        } 
        catch (ex) { 
          Ext.Error.raise({
            response: response,
            json: response.responseText,
            parseError: ex,
            msg: 'Unable to parse the JSON returned by the server: ' + ex.toString()
          });
        } 
        //<debug>
        if (!data) { 
          Ext.Error.raise('JSON object not found');
        } 
        //</debug>
    
    
        return data;
      },
    });

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..."