Extjs4.2 grid datastore读取xml和json

前端之家收集整理的这篇文章主要介绍了Extjs4.2 grid datastore读取xml和json前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

1. 读取xml文件

var store = Ext.create('Ext.data.Store',{          
        proxy: {  
            type: 'ajax',url: 'js/xmlfile/messages.xml',//项目中的路径  
            reader: {  
                type: 'xml',record: 'Folder'  
            }  
        },sorters: ["Read"],//以这个作为排序      
        params : {  
            Status: 'all'  
        },fields: [               
  
             {name: 'URI'},{name: 'DisplayName'},{name: 'MessageCount'}  
  
        ]          
    });          
      
    store.load({params: {Status: 'all'}});    

2. 后台读取xml字符串(非xml对象)。
var store = Ext.create('Ext.data.Store',url: '...',reader: {  
                type: 'xml',fields: [  
             {name: 'URI'},{name: 'MessageCount'}  
        ]          
    });          
      
    store.load({params: {Status: 'all'}}); 

附上xml,可存成文件,可当作字符串返回给前台
    <Folders>  
        <Folder>  
            <URI>/vmrest/mailBox/folders/inBox</URI>  
            <DisplayName>InBox</DisplayName>  
            <MessageCount>3</MessageCount>  
        </Folder>  
        <Folder>  
            <URI>/vmrest/mailBox/folders/deleted</URI>  
            <DisplayName>Deleted</DisplayName>  
            <MessageCount>0</MessageCount>  
        </Folder>  
        <Folder>  
            <URI>/vmrest/mailBox/folders/sent</URI>  
            <DisplayName>Sent</DisplayName>  
            <MessageCount>0</MessageCount>  
        </Folder>  
    </Folders>  

3. 读取json
    var store = Ext.create('Ext.data.Store',{          
            proxy: {  
                type: 'ajax',reader: {  
                    root: 'rows'  
                }  
            },fields: [               
      
                 {name: 'URI'},{name: 'MessageCount'}  
      
      
            ]          
        });   

json字符串格式:
{rows:[{URI: 'aaa',DisplayName: 'bbb',MessageCount: 1},{URI: 'ccc',DisplayName: 'ddd',MessageCount: 2}]} 
原文链接:https://www.f2er.com/xml/299231.html

猜你在找的XML相关文章