Ext学习心得2
2010-04-20 17:17
239 查看
http://www.extjs.com/forum/showthread.php?74361-Solved-JsonStore-and-asp.net-web-service/page3
继上篇,由于我用的是web service所以返回的是XML,所以重写了原来的的TreeLoader
//根据Ext官方的那个重写了TreeLoader的方法
PostTreeLoader = Ext.extend(Ext.tree.TreeLoader, {
requestData: function(node, callback) {
if (this.fireEvent("beforeload", this, node, callback) !== false) {
this.transId = Ext.Ajax.request({
method: this.requestMethod,
url: this.dataUrl || this.url,
success: this.handleResponse,
failure: this.handleFailure,
scope: this,
argument: { callback: callback, node: node },
jsonData: this.getParams(node),
headers: { 'Content-Type': 'application/json; charset=utf-8;' }
});
} else {
// if the load is cancelled, make sure we notify
// the node that we are done
if (typeof callback == "function") {
callback();
}
}
},
processResponse: function(response, node, callback) {
var json = response.responseText;
try {
var o = eval("(" + json + ")").d;
for (var i = 0, len = o.length; i < len; i++) {
var n = this.createNode(o[i]);
if (n) {
node.appendChild(n);
}
}
if (typeof callback == "function") {
callback(this, node);
}
} catch (e) {
this.handleFailure(response);
}
}
});
其他都没变,就改写了上面的2个事件中红色的部分,害我为了这个tree搞了半天。
文章开头的那个链接是关于store的,老外果然很有想法,Store主要的问题还是关于那个返回的那个D,
var store = new Ext.data.JsonStore({
proxy: new Ext.data.HttpProxy({
url: "Home.asmx/LoadPersonInfo"
, method: 'post'
, jsonData: {}
, headers: { 'Content-Type': 'application/json; charset=utf-8;' }
}),
root: 'd.root',
totalProperty: 'd.totalPorperty',
idProperty: 'personId',
fields: fields
});
上面D对象的属性可以自己的,不一定就那个。
后台XX.asmx.cs
var json = new { totalPorperty = MainTypeListCount, root = data };
return json;
上面是返回STORE的最后2句,json的返回对象是object,目的是为了去掉d:后面的那个大双引号。如果还有不明白的可以回复或者看那个链接老外的解决过程。小弟我这里也只能抛砖引玉了。
最后忘记了TreeLoader获得到的JSON语句也要是上面的那种对象形式。可怜我以前都是用Newtonsoft.Json转换成字符串再return,苦了几天了。
继上篇,由于我用的是web service所以返回的是XML,所以重写了原来的的TreeLoader
//根据Ext官方的那个重写了TreeLoader的方法
PostTreeLoader = Ext.extend(Ext.tree.TreeLoader, {
requestData: function(node, callback) {
if (this.fireEvent("beforeload", this, node, callback) !== false) {
this.transId = Ext.Ajax.request({
method: this.requestMethod,
url: this.dataUrl || this.url,
success: this.handleResponse,
failure: this.handleFailure,
scope: this,
argument: { callback: callback, node: node },
jsonData: this.getParams(node),
headers: { 'Content-Type': 'application/json; charset=utf-8;' }
});
} else {
// if the load is cancelled, make sure we notify
// the node that we are done
if (typeof callback == "function") {
callback();
}
}
},
processResponse: function(response, node, callback) {
var json = response.responseText;
try {
var o = eval("(" + json + ")").d;
for (var i = 0, len = o.length; i < len; i++) {
var n = this.createNode(o[i]);
if (n) {
node.appendChild(n);
}
}
if (typeof callback == "function") {
callback(this, node);
}
} catch (e) {
this.handleFailure(response);
}
}
});
其他都没变,就改写了上面的2个事件中红色的部分,害我为了这个tree搞了半天。
文章开头的那个链接是关于store的,老外果然很有想法,Store主要的问题还是关于那个返回的那个D,
var store = new Ext.data.JsonStore({
proxy: new Ext.data.HttpProxy({
url: "Home.asmx/LoadPersonInfo"
, method: 'post'
, jsonData: {}
, headers: { 'Content-Type': 'application/json; charset=utf-8;' }
}),
root: 'd.root',
totalProperty: 'd.totalPorperty',
idProperty: 'personId',
fields: fields
});
上面D对象的属性可以自己的,不一定就那个。
后台XX.asmx.cs
var json = new { totalPorperty = MainTypeListCount, root = data };
return json;
上面是返回STORE的最后2句,json的返回对象是object,目的是为了去掉d:后面的那个大双引号。如果还有不明白的可以回复或者看那个链接老外的解决过程。小弟我这里也只能抛砖引玉了。
最后忘记了TreeLoader获得到的JSON语句也要是上面的那种对象形式。可怜我以前都是用Newtonsoft.Json转换成字符串再return,苦了几天了。
相关文章推荐
- Ext学习心得(一)
- Ext学习心得1
- Ext.js学习心得二
- ext的学习心得
- 黑马程序员—17—java基础:有关API的使用学习笔记和心得体会
- 正则表达式学习心得
- 黑马程序员—20—java基础:有关GUI图形用户界面学习笔记和学习心得体会
- VC++深入详解-第五章学习心得
- Ext.Net学习笔记04:Ext.Net布局
- python 学习心得
- ExtJS学习------Ext.Msg.show()学习
- Potrace学习心得
- 学习java心得 二
- linux学习心得之vim/Cvim篇
- 我的MYSQL学习心得(十三) 权限管理
- SIFT算法学习心得
- ExtJS学习------Ext.window属性详解
- 容器遍历之foreach学习心得
- 3月30及31日学习心得
- Java入门1.2.3—一个老鸟的Java学习心得