Results 1 to 3 of 3

Thread: Sencha touch 2.4.2: Reading json data from a store not working

  1. #1
    Sencha User
    Join Date
    Mar 2016
    Posts
    4

    Default Answered: Sencha touch 2.4.2: Reading json data from a store not working

    I am trying to read json data from a rest service into a data store in my Sencha Android application. When I add the data directly to the store the application launches on my emulator and works fine. However, when I replace the data with a proxy call to my rest service as shown in the view I have provided, all I get is a blue screen with three blinking dots.

    I have also tried using jsonp type at the proxy instead of rest as well as adding autoLoad: 'true'.

    What could be the problem and how can I resolve this?

    Here is my view:
    Code:
    Ext.define('MyApp.view.BigStoryList',{
        extend: 'Ext.List',
        xtype: 'bigStoryList',
        id: 'bigStoryListView',
        config: {
            xtype: 'list',
            scrollable: {
                   direction: 'vertical'
               },
            store: Ext.create('MyApp.store.BigStoryList'),
            itemTpl: '<div>'
            + '<img class="big-image" src="{ImageURL}"/>'
            + '<h5 class="category-label {Category}"><span>{Category}</span></h5>'
            + '<h5 class="big-story-title"><span>{Title}</span></h5>'
            + '</div>'
        }
    });
    Here is my data store:
    Code:
    Ext.define('MyApp.store.BigStoryList', {
        extend : 'Ext.data.Store',
        config : {
            model: 'MyApp.model.BigStoryList',
            proxy: {
                type: 'rest',
                url : 'http://myUrl:8080/myRestService/webresources/service?category=all',
                reader: {
                    type: 'json',
                    root: 'News'
                }
            }
        }
    });
    Here is my model:
    Code:
    Ext.define('MyApp.model.BigStoryList', {
        extend : 'Ext.data.Model',
        config : {
            fields : [{
                name : 'Title',
                type : 'string'
            }, {
                name : 'ImageURL',
                type : 'string'
            }, {
                name : 'Category',
                type : 'string'
            }]
        }
    });
    And here is what my json data looks like:

    Code:
    {
        "News": [{
            "Title": "A title",
            "Link": "http://myUrl/news/some-story-article/",
            "Date": "Mon, 30 May 2016 05~00~02 +0000",
            "Author": "an author",
            "ImageURL": "http://myUrl/myImage.jpg",
            "Content": "Some content goes here",
            "Category": "category1"
        }, {
            "Title": "A title",
            "Link": "http://myUrl/news/some-story-article/",
            "Date": "Sun, 29 May 2016 15~40~12 +0000",
            "Author": "an author",
            "ImageURL": "http://myUrl/myImage.jpg",
            "Content": "Some content goes here",
            "Category": "category2"
        }]
    }
    Thank you.

  2. The only issue I see is in your view definition. You should not create a new instance of the store on the view definition. Instead, define the store the new view is going to use. For your case, change it to store:'BigStoryList'

  3. #2
    Sencha User alex.volfson's Avatar
    Join Date
    Jan 2016
    Posts
    462
    Answers
    60

    Default

    The only issue I see is in your view definition. You should not create a new instance of the store on the view definition. Instead, define the store the new view is going to use. For your case, change it to store:'BigStoryList'

  4. #3
    Sencha User
    Join Date
    Mar 2016
    Posts
    4

    Default Thanks

    I changed the proxy type in the store from 'rest' to 'ajax' and that seemed to do the trick.

    Thank you for the tip about how to add the store to the view the right way.

Similar Threads

  1. Reading Hebrew data from JSON through data store is gibberish
    By lolika in forum Sencha Touch 2.x: Q&A
    Replies: 1
    Last Post: 3 Aug 2015, 8:27 AM
  2. Sencha Touch XML data reading problem
    By Abhijitdd in forum Sencha Touch 2.x: Q&A
    Replies: 5
    Last Post: 18 Jun 2012, 8:53 PM
  3. List with root element in very siple json data not working in sencha touch 2
    By sachin sachdeva in forum Sencha Touch 2.x: Q&A
    Replies: 4
    Last Post: 2 May 2012, 4:40 AM
  4. Help ---List with root element in very siple json data not working in sencha touch 2
    By sachin sachdeva in forum Sencha Touch 2.x: Discussion
    Replies: 1
    Last Post: 27 Apr 2012, 5:05 AM

Tags for this Thread

Posting Permissions

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