1

我正在尝试从托管在本地服务器上的 json 文件中加载一些数据,但是XMLHttpRequest cannot load http://localhost:8080/data.json?_dc=1355779280677&page=1&start=0&limit=25. Origin null is not allowed by Access-Control-Allow-Origin. "一旦应用程序加载,我就会收到错误消息。我的列表中没有填充记录。

我的代码如下。

Ext.define('POC.view.HomePage', {
    extend: 'Ext.TabPanel',
    requires:['Ext.TitleBar','Ext.dataview.List',
    'Ext.Ajax','Ext.data.proxy.Ajax'],
    xtype:'homePage', 
    alias: 'widget.wuHomePageView',

     config: {
     fullscreen: true,
        items: [
        {
          title: 'Home',
          iconCls: 'home',

          items: [

       {
    xtype: 'list',
        title: 'Sample',
        height: '100%',
        onItemDisclosure: true,

        store: {
        autoLoad: true,
        fields: ['name'],
            proxy: {
           type: 'json',
           url: 'http://localhost:8080/data.json',
            reader: {
               type: 'ajax',
               rootProperty: 'stores'
                }
                }
                },
             itemTpl: '{name}',

                }],

                },
            {
            title: 'Contact',
            iconCls: 'user',
            html: 'Contact Screen'
                }
            ]
            },

});

我的 Json 文件如下。

{
    "stores": [
        {
            "name": "Science Gallery",
            "logo": "sciencegallery.jpg",
            "desc": "Get some food",
            "telephone": "016261234",
            "city": "Dublin",
            "add1": "Pearse Street",
            "post": "2",
            "country": "Ireland",
            "latitude": "53.34422",
            "longitude": "-6.25006",
            "menu": [
                {
                    "item": "SC Sandwich"
                },
                {
                    "item": "SC Toasted Sandwich"
                },
                {
                    "item": "SC Panini"
                },
                {
                    "item": "SC Ciabatta"
                },
                {
                    "item": "SC Burrito"
                }
            ]
        },
        {
            "name": "Spar",
            "logo": "spar.jpg",
            "desc": "Get some food",
            "telephone": "016261234",
            "city": "Dublin",
            "add1": "Mayor Street",
            "post": "2",
            "country": "Ireland",
            "latitude": "53.34422",
            "longitude": "-6.25006",
            "menu": [
                {
                    "item": "Spar Sandwich"
                },
                {
                    "item": "Spar Toasted Sandwich"
                },
                {
                    "item": "Spar Panini"
                },
                {
                    "item": "Spar Ciabatta"
                },
                {
                    "item": "Spar Burrito"
                }
            ]
        }
    ]
}

请帮忙。

谢谢

4

1 回答 1

1

没有像json代理这样的东西!您必须使用 ajax 代理:

proxy: {
   type: 'ajax',
   .....
}
于 2012-12-17T20:56:39.497 回答