如何将数据从data.store提取到数组? [英] How to extract the data from data.store to an array?

查看:100
本文介绍了如何将数据从data.store提取到数组?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这里是我的xml代码:

 <?xml version =1.0encoding =UTF-8? > 
< root>
<投资者>
< investor name =Active/>
< investor name =Aggressive/>
< investor name =保守/>
< 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>
< price>
< 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() '< 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:新Ext.data.XmlR eader({
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} 

不能为我工作
请帮助
谢谢你

解决方案

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



假设这只是你的问题的打字错误,如果getRange()没有返回一系列记录,那么可能是你的商店没有正确加载记录。你确定你的商店是否正确加载记录?



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



你需要听商店的加载事件,并且有一个处理程序来操纵数据。



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());
});


});

您应该能够在Firebug控制台中看到一个Ext.data.Record对象数组。 / p>

here is my xml code:

<?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>

here is my code:

    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());


});

the data which is stored in the "prstore",i want it to copy it into an array.

i want the output something like:

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

but it's not working for me please help thank you

解决方案

getRange() ought to do it. Make sure the "R" is capitalized.

Assuming that's just a typo in your question, if getRange() isn't returning an array of records, it's likely that your store is not loading records properly. Are you sure your store is loading the records properly? Use firebug to inspect the store after load.

EDIT Looks like you're running getRange() before the store is done loading the data. You're loading the store upon creation (autoLoad:true), but then you're immediately running getRange() (while the XMLHttpRequest is still pending in the background!).

You'll need to listen for the store's load event, and have a handler to manipulate the data.

EDIT2 This Works:

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());
            });


    });

You should be able to see an array of Ext.data.Record objects in your firebug console.

这篇关于如何将数据从data.store提取到数组?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆