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,可存成文件,可当作字符串返回给前台。

<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',
            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.2 grid datastore读取xml和json

最多只允许输入30个字

加入CSDN,享受更精准的内容推荐,与500万程序员共同成长!
关闭
关闭