Can't get jSon dataStore into ExtJS (Sencha Touch) chart: displays error “cannot read property 'length' of undefined”

拈花ヽ惹草 提交于 2019-11-29 16:27:24
Shazia

I solved this issue with the help of a Sencha folk. Thanks Dan. Here is the solution:

  1. run the sample on a web server as loading JSON files from the file system can sometimes cause problems.
  2. Structure the json data as below

    {
        "data": [
            {
                "School": "Dukes",
                "wins": "3"
            },
            {
                "School": "Emmaus",
                "wins": "10"
            },
            {
                "School": "Maryland",
                "wins": "5"
            },
            {
                "School": "Virginia",
                "wins": "2"
            }
        ]
    }
    
  3. Use the below data store

    window.store1 = new Ext.data.Store({
        model: 'Details',
        proxy: {
            type: 'ajax',
            url: 'GetDataset.json',
            reader: {
                root: 'data',
                type: 'json'
            }
        },
        autoLoad: true
    });
    
rivanov

I'm guessing here, but it seems like a problem I've had before. I believe the problem is with the proxy. Try:

proxy: {
    type: 'rest',
    url: 'http://localhost:2650/AjaxWCFService.svc/GetDataset', 
    reader: {
        root: 'data'
    }

},

Now, you need to define the callback function for the proxy. There's an elegant way with some config, but I honsetly don't know how to do that, so I found out a different solution at the time, the hard way, which is to wrap the JSON which your service returns inside of(like they do here):

Ext.data.JsonP.callback1();

If none of that works, also consider adding the following to your proxy, and emitting a 'total' as part of your JSON response.

totalProperty: 'total'

But keep in mind that I really don't think this will help much at all and that I'm just throwing these ideas out based on a working sample I have.

Try reading this and this. And most of all good luck, that's all of the top of my head mate. Also have a look at this post.

I hope that points you in the right direction. Like I said, I'm not sure, this is my best guess. I'm probably wrong.

Cheers rivanov

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!