Something wrong with my XML?

天大地大妈咪最大 提交于 2019-12-13 03:39:46

问题


i'm parsing an xml with my extjs but it returns only one of the five components.

only the first one of the five components.

Ext.regModel('Card', {
    fields: ['investor']    
});

var store = new Ext.data.Store({
    model: 'Card',
    proxy: {
        type: 'ajax',
        url: 'xmlformat.xml',
        reader: {
            type: 'xml',
            record: 'investors'
        }
    },
    listeners: {
        single: true,
        datachanged: function(){
            Ext.getBody().unmask();
            var items = [];
            store.each(function(rec){
                                        alert(rec.get('investor'));

            });

and my xml file is:

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

wen i run the code only "Active" comes out. . . .

i know that i'm doing something wrong but i'm not sure what....

please help . . . . .


回答1:


Every thing was fine execpt that my xml format should be like this:

Active 3 Month Expiry $0.5 Aggressive LEAPS $0.05 Conservative Monthlies $1 Day Trader Monthly Expiries $22 Very Active Weeklies $100.34

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



回答2:


You need to visit the sencha.com tutorial on how to use XML with a grid. XML Grid Sample

You should take not of how to properly structure your XML so that it can be consumed by a data store.




回答3:


The Ext XML grid needs to be configured to look for the repeating elements to map to each record in your store/grid. You had it configured for investors, of which there is only 1. Then you mapped a field for investor and it is just grabbing the first one that it encounters for the "column" of that "row".

The repeating element for your "rows" in the grid should be investor, not investors.

Change: record: 'investors' to: record: 'investor'



来源:https://stackoverflow.com/questions/4645294/something-wrong-with-my-xml

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!