0

我的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> 
  <event>Weeklies Expiry</event> 
  </events>
 <prices>
  <price>0.05</price> 
  <price>0.5</price> 
  <price>1</price> 
  <price>1</price> 
  <price>22</price> 
  <price>100.34</price> 
  </prices>
  </root>

我的 ExtJS 代码是:

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

    var store = new Ext.data.Store({
        model: 'Card',
        proxy: {
            type: 'ajax',
            url: 'http:/.../initpicker.php',
            reader: {
                type: 'xml',
                record: 'root'
            }
        },
        listeners: {
            single: true,
            datachanged: function(){
                var items = [];
                store.each(function(r){
                stocks.push({text: '<span style="color:Blue;font-weight:bolder;font-size:30px;">'+ r.get('price') +'</span>'});
                values.push({text: '<span style="font-weight: bold;font-size:25px;">'+ r.get('investor') +'</span>'});
                points.push({text: '<span style="font-weight: bold;font-size:25px;">'+ r.get('event') +'</span>'});
                });
            }
        }    
    });
    store.read();

我的问题是,如果我的 xml 包含五次相同的标签,我们仍然可以解析数据。. . . .?

我试过这段代码,但它只解析了第一个............

如果有其他方法请建议。. .

谢谢你。

4

3 回答 3

3

这真的取决于你的记录是什么样的。

第一个投资者元素是否应该与第一个事件和价格元素相关并捆绑到单个记录中?第二条记录呢?它会包含 Aggressive、LEAPS 和 0.5 作为数据值吗?如果是这样,那么 XML 就没有多大意义了。

我不相信 Sencha 的 XmlReader 能很好地处理这个问题,这可以解释为什么你只获得第一条记录。

有两种解决方案:

  1. 修改正在生成的 XML 以对 XmlReader 更有意义
  2. 编写您自己的 Reader 类以从您可用的数据格式中解析和提取记录
于 2011-01-11T13:34:23.333 回答
0

你用这个 XML 做什么?

我假设它是用于网格的。此外,您的代码似乎与 XML 中的标签不匹配。你想在你的代码中获取什么数据?设置数据对象时,您应该从 XML 中的标记访问数据。

我建议您重新考虑 XML 的结构。您的标签不描述标签中包含的数据。在某些方面,您似乎错过了 XML 的重点。

像这样的东西应该是填充网格所需要的。

<investors>
<investor>
    <name>Bob</name>
    <style>Aggressive</style>
    <price>0.5</price>
</investor>
<investor>
    <name>Francis</name>
    <price>150.00</price>
    </investor>
</investors>

我强烈建议您查看此链接: Sencha Webste 的 XML Grid Sample

于 2011-01-12T01:04:25.677 回答
0

您可以使用 ExtJs 解析 xml。但是xml文件应该在同一个域中

于 2011-01-12T04:56:28.170 回答