如何在SenCha Touch中检索XML中的属性值

时间:2014-04-22 15:00:24

标签: xml extjs sencha-touch

我想从xml数据源中检索数据。 但我的问题是我无法通过使用StoreManager来获取商店:

var store = Ext.data.StoreManager.get(' myApp.store.SensorStore');

请查看我的代码并更正。

谢谢

Ext.define('myApp.model.SensorStation', {
    extend: 'Ext.data.Model',
    requires: ['Ext.MessageBox', 'Ext.data.reader.Xml'],
    config: {
        fields: [{

            name: 'name',
            type: 'string',
            mapping: '@name'
        }, {
            name: 'lat',
            mapping: '@latitude',
            type: 'float'
        }, {
            name: 'lng',
            mapping: '@longitude',
            type: 'float'
        }, {
            name: 'locid',
            mapping: '@locid',
            type: 'string'
        }

        ]
    },
    proxy: {
        type: 'ajax',
        url: 'http://webtrak.bksv.com/mel/configuration',
        reader: {
            type: 'xml',
            rootProperty: 'nmts',
            record: 'locations'
        }
    }
});

//-------------------------------------Store ------------------------

Ext.define('myApp.store.SensorStationStore', {
    extend: 'Ext.data.Store',
    config: {
        model: 'myApp.model.SensorStation',
        storeId: 'SensorStore',
        autoLoad: true
    }

});

Ext.application({
    name: 'myApp',
    requires: ['Ext.MessageBox'],

    launch: function() {
        //------------------------------------------------------------
        var store = Ext.data.StoreManager.get('myApp.store.SensorStore');
        //var store = Ext.getStore('myApp.store.SensorStationStore');
        if (!store) {
            console.log("Store not found");
            Ext.Msg.alert('Not Found', 'Found not Store!');
            return;
        } else {
            console.log("Store found");
            Ext.Msg.alert('Found', 'Found Store!');
            return;
        }
    }
});

这是SenCha Fiddle,您可以将我的代码复制到其中。 https://fiddle.sencha.com/

谢谢

1 个答案:

答案 0 :(得分:0)

你没有将proxy:{}放在你的模型中config:{}。所以,我猜请求不会成功,app的商店也不会被填满。