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', {        
        proxy: {
            type: 'ajax',
            url: '...',
            reader: {
                type: 'xml',
                record: 'Folder'
            }
        },
        sorters: ["Read"],        //以这个作为排序    
        params : {
            Status: 'all'
        },
        fields: [
             {name: 'URI'},
             {name: 'DisplayName'},
             {name: 'MessageCount'}
        ]        
    });        
    
    store.load({params: {Status: 'all'}});  


附上xml,可存成文件,可当作字符串返回给前台。


	
		/vmrest/mailbox/folders/inbox
		Inbox
		3
	
	
		/vmrest/mailbox/folders/deleted
		Deleted
		0
	
	
		/vmrest/mailbox/folders/sent
		Sent
		0
	

3. 读取json

var store = Ext.create('Ext.data.Store', {        
        proxy: {
            type: 'ajax',
            url: '...',
            reader: {
                root: 'rows'
            }
        },        
        fields: [             

             {name: 'URI'},
             {name: 'DisplayName'},
             {name: 'MessageCount'}


        ]        
    }); 

json字符串格式:

{rows:[{URI: 'aaa',DisplayName: 'bbb', MessageCount: 1},{URI: 'ccc',DisplayName: 'ddd',MessageCount: 2}]}

你可能感兴趣的:(extjs4,datastore,xml,json)