【问题标题】:Something wrong with my XML?我的 XML 有问题吗?
【发布时间】:2011-01-10 09:29:47
【问题描述】:

我正在用我的 extjs 解析一个 xml,但它只返回五个组件之一。

只有五个组件中的第一个。

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

            });

我的 xml 文件是:

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

当我运行代码时,只有“活动”出来。 . . .

我知道我做错了什么,但我不确定是什么......

请帮忙。 . . . .

【问题讨论】:

    标签: extjs xml-parsing


    【解决方案1】:

    一切都很好,除了我的 xml 格式应该是这样的:

    积极的 3个月到期 0.5 美元 挑衅的 飞跃 0.05 美元 保守的 月刊 1美元 日内交易者 每月到期 22 美元 很活跃 周刊 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】:

      您需要访问 sencha.com 教程,了解如何将 XML 与网格一起使用。 XML Grid Sample

      您不应该考虑如何正确构建 XML 以便数据存储可以使用它。

      【讨论】:

        【解决方案3】:

        Ext XML 网格需要配置为查找重复元素以映射到存储/网格中的每条记录。你已经为investors 配置了它,其中只有 1 个。然后你为investor 映射了一个字段,它只是抓取它遇到的第一个字段,用于该“行”的“列”。

        网格中“行”的重复元素应该是investor,而不是investors

        更改:record: 'investors' 至:record: 'investor'

        【讨论】:

          猜你喜欢
          • 2015-06-06
          • 2013-09-03
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2010-09-11
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多