2

这是我的xml代码:

<?xml version="1.0" encoding="UTF-8"?>
<root>
<investors>
    <investor name="Active"/>
    <investor name="Aggressive"/>
    <investor name="Conservative"/>
    <investor name="Day Trader"/>
    <investor name="Very Active"/>
</investors>    
<events>
    <event period="3 Month Expiry"/>
    <event period="LEAPS"/>
    <event period="Monthlies"/>
    <event period="Monthly Expiries"/>
    <event period="Weeklies"/>
</events>
<prices>
    <price rate="$0.5"/>
    <price rate="$0.05"/>
    <price rate="$1"/>
    <price rate="$22"/>
    <price rate="$100.34"/>
</prices>   
</root>

这是我的代码:

    Ext.onReady(function(){
                     var hi= [],hello = [], hey = [];
      Ext.getBody().mask(true, '<div class="demos-loading">Loading&hellip;</div>');  
    var tsstore = new Ext.data.Store({    
        url: 'xmlformat.xml',
        autoLoad: true,
        reader: new Ext.data.XmlReader({
               record: 'investor'
           }, [{name: 'name', mapping: '@name'}])
    });

   var evstore = new Ext.data.Store({    
        url: 'xmlformat.xml',
        autoLoad: true,
        reader: new Ext.data.XmlReader({
               record: 'event'
           }, [{name: 'Eve', mapping: '@period'}])
    });

   var prstore = new Ext.data.Store({    
        url: 'xmlformat.xml',
        autoLoad: true,
        reader: new Ext.data.XmlReader({
               record: 'price'
           }, [{name: 'Pri', mapping: '@rate'}])
    });
    var tsgrid = new Ext.grid.GridPanel({
        store: tsstore,
        columns: [{header: "Trading Style", dataIndex: 'name', sortable: true}],
        renderTo:'example-grid',
        width:540,
        height:200
    });
    var evgrid = new Ext.grid.GridPanel({
        store: evstore,
        columns: [{header: "Events", dataIndex: 'Eve', sortable: true}],
        renderTo:'example-gridone',
        width:540,
        height:200
    });
    var prgrid = new Ext.grid.GridPanel({
        store: prstore,
        columns: [{header: "Price", dataIndex: 'Pri', sortable: true}],
        renderTo:'example-gridtwo',
        width:540,
        height:200
    });



hello.push(tsstore.getRange());


});

存储在“prstore”中的数据,我希望它把它复制到一个数组中。

我想要输出类似:

hello = {"$0.5","$0.05","$1","$22","$100.34"}

但它对我不起作用请帮助谢谢

4

1 回答 1

5

getRange() 应该这样做。确保“R”大写。

假设这只是您的问题中的一个错字,如果 getRange() 没有返回记录数组,则您的商店可能没有正确加载记录。您确定您的商店正在正确加载记录吗?加载后使用萤火虫检查商店。

编辑 看起来您在商店完成加载数据之前正在运行 getRange() 。您在创建时加载存储 (autoLoad:true),但随后您立即运行 getRange()(而 XMLHttpRequest 仍在后台挂起!)。

您需要监听商店的load事件,并有一个处理程序来操作数据。

EDIT2这个作品:

Ext.onReady(function(){
        console.log('hi');
        var prstore = new Ext.data.Store({
                url: 'xmlformat.xml',
                autoLoad: true,
                reader: new Ext.data.XmlReader({
                        record: 'price'
                    }, [{name: 'Pri', mapping: '@rate'}])
            });

        prstore.on('load',function(store,records,opts){                    
                console.log(store.getRange());
            });


    });

您应该能够在您的萤火虫控制台中看到一组 Ext.data.Record 对象。

于 2011-01-03T05:57:43.977 回答