ExtJS4.2学习 php版(七)

memory方式

Ext.define("User",{
		extend:"Ext.data.Model",
		fields:["id","name","email"]
});

var data = [
		    {
		        "id": 1,
		        "name": "Ed Spencer",
		        "email": "[email protected]"
		    },
		    {
		        "id": 2,
		        "name": "Abe Elias",
		        "email": "[email protected]"
		    }
];

var store = Ext.create("Ext.data.Store",{
		model:"User",
		data:data	
});

store.each(function(result){
	console.log(result);
});

json对象集合 

var data = {
		json:	[
		    {
		        "id": 1,
		        "name": "Ed Spencer",
		        "email": "[email protected]"
		    },
		    {
		        "id": 2,
		        "name": "Abe Elias",
		        "email": "[email protected]"
		    }
		]
}

var store = Ext.create("Ext.data.Store",{
		model:"User",
		data:data,
		proxy:{
			type:"memory",
			reader:{
				type:"json",
				root:"json"	
			}	
		}	
});

ajax json

var store = Ext.create("Ext.data.Store",{
		model:"User",
		proxy:{
			type:"ajax",
			url:"user.php",
			reader:{
				type:"json"	
			}	
		}	
});
store.load({
	scope:this,
	callback:function(record, opreation, success){
		console.log(record);
	}
});

user.php

$arr = array(
	"id" => 2,
	"name" => "sadsads",
	"email" => "sadasdsadsas"
);

$data = json_encode($arr);
echo $data;

ajax json文件

var store = Ext.create("Ext.data.Store",{
		model:"User",
		proxy:{
			type:"ajax",
			url:"user.json",
			reader:{
				type:"json"	
			}	
		}	
});

user.json

[
    {
        "firstName": 'Ed',
        "lastName": 'Spencer'
    },
    {
        "firstName": 'Tommy',
        "lastName": 'Maintz'
    }
]

ajax xml文件

Ext.define("User",{
		extend:"Ext.data.Model",
		fields:["id","name","email"]	
});

var store = Ext.create("Ext.data.Store",{
		model:"User",
		proxy:{
				type:"ajax",
				url:"user.xml",
				reader:{
						type:"xml",
						record:"user",
						root:"users"	
				}	
		}	
});

user.xml

<?xml version="1.0" encoding="UTF-8"?>
<users>
    <user>
        <id>1</id>
        <name>Ed Spencer</name>
        <email>[email protected]</email>
    </user>
    <user>
        <id>2</id>
        <name>Abe Elias</name>
        <email>[email protected]</email>
    </user>
</users>


你可能感兴趣的:(ExtJs)