1

Is there a way to output the json-string read by my store in sencha touch 2?

My store is not reading the records so I'm trying to see where went wrong. My store is defined as follows:

Ext.define("NotesApp.store.Online", {
    extend: "Ext.data.Store",
           config: {
           model: 'NotesApp.model.Note',
           storeId: 'Online',
           proxy: {
               type: 'jsonp',
               url: 'http://xxxxxx.com/qa.php',
               reader: {
                   type: 'json',
                   rootProperty: 'results'
               }
           },
           autoLoad: false,
           listeners: {
               load: function() {   
                    console.log("updating");
                   // Clear proxy from offline store
                   Ext.getStore('Notes').getProxy().clear();
                   console.log("updating1");
                   // Loop through records and fill the offline store


                    this.each(function(record) {
                             console.log("updating2");
                             Ext.getStore('Notes').add(record.data);

                   });

                   // Sync the offline store
                   Ext.getStore('Notes').sync();
                   console.log("updating3");
                   // Remove data from online store
                   this.removeAll();
                    console.log("updated");
               }

           },
           fields: [
                    {
                    name: 'id'
                    },
                    {
                    name: 'dateCreated'
                    },
                    {
                    name: 'question'
                    },
                    {
                    name: 'answer'
                    },
                    {
                    name: 'type'                    
                    },
                    {
                    name: 'author'
                    }
                    ]
           }
});
0

4 Answers 4

1

you may get all the data returned by the server through the proxy, like this:

store.getProxy().getReader().rawData
Sign up to request clarification or add additional context in comments.

Comments

1

You can get all the data (javascript objects) returned by the server through the proxy as lasaro suggests:

store.getProxy().getReader().rawData

To get the JSON string of the raw data (the reader should be a JSON reader) you can do:

Ext.encode(store.getProxy().getReader().rawData)

//or if you don't like 'shorthands':
Ext.JSON.encode(store.getProxy().getReader().rawData)

You can also get it by handling the store load event:

// add this in the store config
listeners: {
    load: function(store, records, successful, operation, eOpts) {
        operation.getResponse().responseText
    }
}

Comments

0

As far as I know, there's no way to explicitly observe your response results if you are using a configured proxy (It's obviously easy if you manually send a Ext.Ajax.request or Ext.JsonP.request).

However, you can still watch your results from your browser's developer tools.

For Google Chrome:

When you start your application and assume that your request is completed. Switch to Network tab. The hightlighted link on the left-side panel is the API url from which I fetched data. And on the right panel, choose Response. The response result will appear there. If you have nothing, it's likely that you've triggered a bad request.

dev tool

Hope this helps.

Comments

0

Your response json should be in following format in Ajax request

{results:[{"id":"1", "name":"note 1"},{"id":"2", "name":"note 2"},{"id":"3", "name":"note 3"}]}

id and name are properties of your model NOte.

For jsonp,

in your server side, get value from 'callback'. that value contains a name of callback method. Then concat that method name to your result string and write the response.

Then the json string should be in following format

callbackmethod({results:[{"id":"1", "name":"note 1"},{"id":"2", "name":"note 2"},{"id":"3", "name":"note 3"}]});

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.