본문 바로가기

IT-Consultant

extjs에서 json으로 데이터를 가져올때 데이터 접근 방법 명시

Ext.onReady(function() {

	var ds = new Ext.data.Store({
				remoteSort : true,
				proxy : new Ext.data.HttpProxy({
							url : 'http://extjs.ekms.com:8080/samples/html/data.json'
						}),
				reader : new Ext.data.JsonReader({
							root : 'response.data.userlist',
							autoLoad : true,
							totalProperty : 'response.trxCount',
							id : 'userid'
						}, ['userid','username'])
			});


	var grid = new Ext.grid.GridPanel({
				renderTo : document.body,
				frame : true,
				title : 'Json Test',
				height : 200,
				width : 500,
				store : ds,
				columns : [{
							header : "Post ID",
							dataIndex : 'userid'
						},{
                            header : "username",
                            dataIndex : 'username'
                        }]
			});
    ds.load();

});



{
	"response" : {
		"trxCount" : 0,
		"data" : {
			"userlist" : [{
						"userid" : "GG",
						"username" : "sdfg"
					}, {
						"userid" : "AA",
						"username" : "CCC"
					}, {
						"userid" : "HH",
						"username" : "asdf"
					}, {
						"userid" : "II",
						"username" : "sdf"
					}, {
						"userid" : "JJ",
						"username" : "asdfasccc"
					}, {
						"userid" : "CC",
						"username" : "test"
					}, {
						"userid" : "DD",
						"username" : "test2"
					}, {
						"userid" : "EE",
						"username" : "asdf"
					}, {
						"userid" : "FF",
						"username" : "asdfasd"
					}, {
						"userid" : "BB",
						"username" : "홍길동"
					}]
		},
		"trxMessage" : "",
		"error" : false,
		"errorCode" : ""
	}
}