高分!新手求助,几个关于extjs4的问题

种草德鲁伊 2012-12-27 06:01:30
1. 在处理list-detail的时候,有必要定义多个model和store吗?更新详细信息的时候,应该用store还是ajax自己处理?

2. ajax可以发送x-www-form-urlencoded格式的内容吗?

3. json序列化会返回一个奇怪的时间格式,grid可以用renderer解决,form就比较麻烦了,除了更改序列化的方式外,有没有更好的方法?每次都进行转换又比较烦

4. 官方竟然没提供DateTimeField?好囧

5. 官方有没有提供从xml读取tree数据的方法?
...全文
314 19 打赏 收藏 转发到动态 举报
写回复
用AI写文章
19 条回复
切换为时间正序
请发表友善的回复…
发表回复
think0201 2013-01-19
  • 打赏
  • 举报
回复
高手们,我又学习了!
种草德鲁伊 2013-01-19
  • 打赏
  • 举报
回复
引用 17 楼 KarasCanvas 的回复:
引用 14 楼 jason_dct 的回复:引用 12 楼 KarasCanvas 的回复:又发现一个问题,ext的ajaxrequest没有同步模式? 可以啊 Ext.Ajax.request({ url: "myProxy.ashx", method: "GET", asy……
看源码才注意到,那个竟然是私有属性?当然js没这样的机制,要用还是能用。 问题基本都解决了。
种草德鲁伊 2013-01-02
  • 打赏
  • 举报
回复
引用 14 楼 jason_dct 的回复:
引用 12 楼 KarasCanvas 的回复:又发现一个问题,ext的ajaxrequest没有同步模式? 可以啊 Ext.Ajax.request({ url: "myProxy.ashx", method: "GET", async: false, //ASYNC 是……
4.1的文档里确实没这个参数,不过自己定义几个函数也没什么
段传涛 2012-12-31
  • 打赏
  • 举报
回复
有点长 看这个 http://blog.csdn.net/jason_dct/article/details/8454280
段传涛 2012-12-31
  • 打赏
  • 举报
回复
3. json序列化会返回一个奇怪的时间格式,grid可以用renderer解决,form就比较麻烦了,除了更改序列化的方式外,有没有更好的方法?每次都进行转换又比较烦 4. 官方竟然没提供DateTimeField?好囧 5. 官方有没有提供从xml读取tree数据的方法? ----------------------------------- json很好用是要转换的, 应该不麻烦吧。 同理,需要写代码 5.参考代码如下
段传涛 2012-12-31
  • 打赏
  • 举报
回复
引用 12 楼 KarasCanvas 的回复:
又发现一个问题,ext的ajaxrequest没有同步模式?
可以啊 Ext.Ajax.request({ url: "myProxy.ashx", method: "GET", async: false, //ASYNC 是否异步( TRUE 异步 , FALSE 同步) params: { //将真正的页面(服务)url参数传递到代理页面 u: url, m: "GET", t: "" },
H_Gragon 2012-12-31
  • 打赏
  • 举报
回复
引用 3 楼 KarasCanvas 的回复:
第二个问题已经解决了,是我误解params参数的意思了,以为是附加到querystring里的。
买切糕去了
种草德鲁伊 2012-12-29
  • 打赏
  • 举报
回复
又发现一个问题,ext的ajaxrequest没有同步模式?
Assassin_ 2012-12-28
  • 打赏
  • 举报
回复
引用 7 楼 KarasCanvas 的回复:
引用 5 楼 yumen3501 的回复:1.更新的时候store吧。 既然用ext了 。还是用store 问题是这样的,比如我要显示文章列表,只需要显示文章标题,服务端提供的列表数据也只有id和标题,这时候有没有必要定义一个简化版的列表model? 但是这样一来,就没办法通过store来同步数据了
就没办法通过store来同步数据了 ->什么意思?store数据可以动态更新!
种草德鲁伊 2012-12-28
  • 打赏
  • 举报
回复
引用 5 楼 yumen3501 的回复:
1.更新的时候store吧。 既然用ext了 。还是用store
问题是这样的,比如我要显示文章列表,只需要显示文章标题,服务端提供的列表数据也只有id和标题,这时候有没有必要定义一个简化版的列表model? 但是这样一来,就没办法通过store来同步数据了
Assassin_ 2012-12-28
  • 打赏
  • 举报
回复
忘记了 。 Ext.app.MyXMLLoader 是一个解析到xml的扩展 引用到页面就行。 官方有下载!

/*
* Ext JS Library 2.2.1
* Copyright(c) 2006-2009, Ext JS, LLC.
* licensing@extjs.com
*
* http://extjs.com/license
*/

/**
* @class Ext.ux.XmlTreeLoader
* @extends Ext.tree.TreeLoader
* <p>A TreeLoader that can convert an XML document into a hierarchy of {@link Ext.tree.TreeNode}s.
* Any text value included as a text node in the XML will be added to the parent node as an attribute
* called <tt>innerText</tt>.  Also, the tag name of each XML node will be added to the tree node as
* an attribute called <tt>tagName</tt>.</p>
* <p>By default, this class expects that your source XML will provide the necessary attributes on each
* node as expected by the {@link Ext.tree.TreePanel} to display and load properly.  However, you can
* provide your own custom processing of node attributes by overriding the {@link #processNode} method
* and modifying the attributes as needed before they are used to create the associated TreeNode.</p>
* @constructor
* Creates a new XmlTreeloader.
* @param {Object} config A config object containing config properties.
*/
Ext.ux.XmlTreeLoader = Ext.extend(Ext.tree.TreeLoader, {
    /**
    * @property  XML_NODE_ELEMENT
    * XML element node (value 1, read-only)
    * @type Number
    */
    XML_NODE_ELEMENT: 1,
    /**
    * @property  XML_NODE_TEXT
    * XML text node (value 3, read-only)
    * @type Number
    */
    XML_NODE_TEXT: 3,

    // private override
    processResponse: function (response, node, callback) {
        var xmlData = response.responseXML;
        var root = xmlData.documentElement || xmlData;

        try {
            node.beginUpdate();
            node.appendChild(this.parseXml(root));
            node.endUpdate();

            if (typeof callback == "function") {
                callback(this, node);
            }
        } catch (e) {
            this.handleFailure(response);
        }
    },

    // private
    parseXml: function (node) {
        var nodes = [];
        Ext.each(node.childNodes, function (n) {
            if (n.nodeType == this.XML_NODE_ELEMENT) {
                var treeNode = this.createNode(n);
                if (n.childNodes.length > 0) {
                    var child = this.parseXml(n);
                    if (typeof child == 'string') {
                        treeNode.attributes.innerText = child;
                    } else {
                        treeNode.appendChild(child);
                    }
                }
                nodes.push(treeNode);
            }
            else if (n.nodeType == this.XML_NODE_TEXT) {
                var text = n.nodeValue.trim();
                if (text.length > 0) {
                    return nodes = text;
                }
            }
        }, this);

        return nodes;
    },

    // private override
    createNode: function (node) {
        var attr = {
            tagName: node.tagName
        };

        Ext.each(node.attributes, function (a) {
            attr[a.nodeName] = a.nodeValue;
        });

        this.processAttributes(attr);

        return Ext.ux.XmlTreeLoader.superclass.createNode.call(this, attr);
    },

    /*
    * Template method intended to be overridden by subclasses that need to provide
    * custom attribute processing prior to the creation of each TreeNode.  This method
    * will be passed a config object containing existing TreeNode attribute name/value
    * pairs which can be modified as needed directly (no need to return the object).
    */
    processAttributes: Ext.emptyFn
});
     
Assassin_ 2012-12-28
  • 打赏
  • 举报
回复
1.更新的时候store吧。 既然用ext了 。还是用store 2.可以 3.什么样的格式啊? 4. 5.可以。我写过一个 。 可以参考一下

 Ext.app.MyXMLLoader = Ext.extend(Ext.ux.XmlTreeLoader, {
        processAttributes: function (attr) {
            attr.id = attr.id;
            attr.href = attr.url;
            attr.text = attr.name;
            attr.url = attr.url;
            attr.leaf = attr.leaf;
        }
    });
    // left Tree
    var menu = new Ext.tree.TreePanel({
        title: '系统菜单',
        region: "west",
        animate: true,
        autoScroll: true,
        enableTabScroll: true,
        collapsible: true,
        collapsed: true,
        split: true,
        rootVisible: true,
        lines: true,
        width: 220,
        minSize: 220,
        maxSize: 220,
        root: new Ext.tree.AsyncTreeNode({
            text: '主菜单',
            draggable: false, // 根节点不容许拖动
            expanded: false
        }),
        loader: new Ext.app.MyXMLLoader({
            preloadChildren: true,
            clearOnLoad: false,
            dataUrl: "/manage/LoadTreeXML" //这里访问到action 里 。然后action解析xml。也可以直接写xml url
        }),
        collapseFirst: false
    });
    menu.expandAll();
    menu.on('click', function (node) {
        if (node.leaf == 'true' && typeof node.leaf != 'undefined') {
            var tab = tabMain.getComponent(node.id);
            if (!tab) {
                tab = tabMain.add({
                    'id': node.id,
                    'title': node.text,
                    closable: true,  //通过html载入目标页
                    html: '<iframe scrolling="auto" frameborder="0" width="100%" height="100%" src="' + node.attributes.upost + '"></iframe>'
                });
            }
            tabMain.setActiveTab(tab);
        }
    });

        /// <summary>
        /// tree xml数据源
        /// </summary>
        /// 
        [SessionFilter]
        public void LoadTreeXML()
        {
            StreamReader sr = new StreamReader(Server.MapPath("\\Content\\xml\\xml-tree-data.xml"));
            Response.ContentType = "text/xml; charset=utf-8";
            string _temp = sr.ReadToEnd();
            sr.Close();
            Response.Write(_temp);
            Response.End(); 
        }
种草德鲁伊 2012-12-28
  • 打赏
  • 举报
回复
糕手们呢,都哪去了
种草德鲁伊 2012-12-28
  • 打赏
  • 举报
回复
第二个问题已经解决了,是我误解params参数的意思了,以为是附加到querystring里的。
种草德鲁伊 2012-12-28
  • 打赏
  • 举报
回复
引用 10 楼 yumen3501 的回复:
一个不行。 获取列表的时候。为什么不把content一起取出 。不显示即可
因为是长字符串,数据可能很大,如果列表里就全部读取出来就很可怕了
Assassin_ 2012-12-28
  • 打赏
  • 举报
回复
引用 9 楼 KarasCanvas 的回复:
引用 8 楼 yumen3501 的回复:就没办法通过store来同步数据了 ->什么意思?store数据可以动态更新! 列表的数据{id, title}, 编辑详细信息的数据{id, title, content},这样不能通过同一个store来读取更新吧
一个不行。 获取列表的时候。为什么不把content一起取出 。不显示即可
种草德鲁伊 2012-12-28
  • 打赏
  • 举报
回复
引用 8 楼 yumen3501 的回复:
就没办法通过store来同步数据了 ->什么意思?store数据可以动态更新!
列表的数据{id, title}, 编辑详细信息的数据{id, title, content},这样不能通过同一个store来读取更新吧
rayaspnet 2012-12-28
  • 打赏
  • 举报
回复
引用 1 楼 rayaspnet 的回复:
extjs
2. ajax可以发送x-www-form-urlencoded格式的内容吗?[/quote] 补充一个extjs的例子(所有的js的ajax都使用的xmlhttprequest)
Ext.Ajax.request({
     url: 'com/functions.cfc',
     success: successMethod,
     failure: errorMethod,
     headers: {"Content-Type": "application/x-www-form-urlencoded; charset=UTF-8"},
     params: {method:'setupLife',argument1:arg1,argument2:arg2}
});
rayaspnet 2012-12-28
  • 打赏
  • 举报
回复
引用 楼主 KarasCanvas 的回复:
ajax可以发送x-www-form-urlencoded格式的内容吗?
可以
<!DOCTYPE html>
<html>
<head>
<script>
function loadXMLDoc()
{
var xmlhttp;
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
    document.getElementById("myDiv").innerHTML=xmlhttp.responseText;
    }
  }
xmlhttp.open("POST","demo_post2.asp",true);
xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
xmlhttp.send("fname=Henry&lname=Ford");
}
</script>
</head>
<body>

<h2>AJAX</h2>
<button type="button" onclick="loadXMLDoc()">Request data</button>
<div id="myDiv"></div>
 
</body>
</html>

http://www.w3schools.com/ajax/tryit.asp?filename=tryajax_post2

62,046

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧