0

我需要从位于远程服务器上的数据源读取内容(我无权修改任何内容)

我已经尝试了几天来获取内容,但是没有用。

然后我所做的是我下载了这个数据源,它是一个 xml 文件,并将它与我的代码放在同一个文件夹下,以测试我的代码语法的正确性,发现代码有效。

但是当我改回外部数据资源(从:url:'app/store/configuration.xml'到:url:' http ://webtrak.bksv.com/mel/configuration ')时,它仍然读取但返回无内容。

这不是由 CORS 问题引起的,因为我正在真实设备上测试我的应用程序。

这是我的商店和模型。请帮忙

Ext.define('myApp.store.SensorStationStore', {
    extend: 'Ext.data.Store',
    requires: ['myApp.model.SensorStation', 'Ext.data.reader.Xml'],
    config:{
        model: 'myApp.model.SensorStation',
        storeId: 'SensorStore',
        autoLoad: true,
        proxy: {
                 type: 'ajax',
                 url: 'http://webtrak.bksv.com/mel/configuration',
                 //url: 'app/store/configuration.xml',
                 reader: {
                     type: 'xml',
                     record: 'locations',
                     rootProperty: 'nmts'
                 }
              }
           }

        });

Ext.define('myApp.model.SensorStation', {
    extend: 'Ext.data.Model',
    config: {
        fields: [
            {

                name: 'name', 
                type: 'string',
                mapping: '@name'
                //convert: function (value, record) {
                //    Ext.Msg.alert(value,record.raw);
                //    //var nodes = rec.raw.querySelectorAll('');
                //}
            },
            {
                name: 'lat',
                mapping: '@latitude',
                type: 'float'
            },
            {
                name: 'lng',
                mapping: '@longitude',
                type: 'float'
            },
            {
                name: 'locid',
                mapping:'@locid',
                type: 'string'
            }
        ]
    }
});

谢谢你。

4

1 回答 1

2

我发现问题出在哪里......我从来没有使用过 XML,所以我不知道 ajax 请求的响应如何,但是通过应用以下代码进行商店将填满你的应用商店(只是一点点改变你的代码)

代码:

Ext.define('myApp.store.SensorStationStore', {
    extend: 'Ext.data.Store',
    requires: ['myApp.model.SensorStation', 'Ext.data.reader.Xml'],
    config:{
        model: 'myApp.model.SensorStation',
        storeId: 'SensorStore',
        autoLoad: true,
        proxy: {
            type: 'ajax',
            url: 'http://webtrak.bksv.com/mel/configuration',
            //url: 'app/store/configuration.xml',
            reader: {
                type: 'xml',
                record: 'locations',
                rootProperty: 'nmts'
            }
        }
    } });

您正在尝试在配置对象之外应用商店配置。干杯!!

于 2014-04-23T12:25:28.030 回答