ext中的reader何proxy

昨晚的发现,用现成的jsonstore满足不了我的需求,因为用jsonstore回来的数据全部用给了页面渲染,而我比如包含了一些totalCount,serverStatus这些属性的话,那岂不是没法映射了?

觉得ext也不会这么弱智,仔细看了下有一个reader,大概看了下用法,之前的store完全可以有现在的一个proxy和reader对象构成。

 

之前的store是这么写的:

var store = new Ext.data.JsonStore({ url : "servlet/statusServlet", root : "datas", fields : ["id", "name", "step1", "step2", "step3", "step4", "status"] });

 

现在这么写了:

// 更换成proxy和reader的形式定义store var proxy = new Ext.data.HttpProxy({ url : "servlet/statusServlet" }); var reader = new Ext.data.JsonReader({ status : "status", root : "datas", fields : [{ name : "id" }, { name : "name" }, { name : "step1" }, { name : "step2" }, { name : "step3" }, { name : "step4" }, { name : "status" }] }); var store = new Ext.data.Store({ proxy : proxy, reader : reader });

 

返回的数据是这样子的:

{"status":"2",datas:[{"id":"1","name":"站点1","step1":"2","step2":"2","step3":"2","step4":"2","status":"2"},{"id":"2","name":"站点2","step1":"2","step2":"2","step3":"2","step4":"2","status":"2"},{"id":"3","name":"站点3","step1":"2","step2":"2","step3":"2","step4":"2","status":"2"},{"id":"4","name":"站点4","step1":"2","step2":"2","step3":"2","step4":"2","status":"2"},{"id":"5","name":"站点5","step1":"2","step2":"1","step3":"0","step4":"0","status":"0"}]}

 

通过用firebug,对ext的debug发现使用这个方法可以把返回数据中的status的值找到:reader.jsonData.status

 

我觉得肯定还有更快捷的封装好的方法,不过目前问题已经解决了,以后遇到了就记住了

 

 

你可能感兴趣的:(Firebug,ext,url)