zoukankan      html  css  js  c++  java
  • Ext学习心得2

    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,苦了几天了。

  • 相关阅读:
    ucore lab4 内核线程管理 学习笔记
    谈谈博客三迁的经历
    ucore lab3 虚拟内存管理 学习笔记
    ucore lab2 物理内存管理 学习笔记
    ucore lab1 操作系统启动过程 学习笔记
    【VMware】在移动硬盘或U盘中安装便携linux系统
    借助ADB冻结与卸载Android系统应用(免ROOT)
    Windows下查找各类游戏存档路径
    QMetaObject::connectSlotsByName: No matching signal for XXX 原理探究
    将VScode添加至右键菜单
  • 原文地址:https://www.cnblogs.com/nbjkj/p/1716366.html
Copyright © 2011-2022 走看看