??xml version="1.0" encoding="utf-8" standalone="yes"?>亚洲国产精品一区二区第四页,亚洲天堂一区在线,亚洲国产乱码最新视频http://m.tkk7.com/boluobn/category/24693.html大江东去,淘?..zh-cnTue, 13 Nov 2007 00:51:33 GMTTue, 13 Nov 2007 00:51:33 GMT60EXT手册QManual:Core:Working with JSON (Chinese) (?http://m.tkk7.com/boluobn/articles/160060.html菠萝菠萝Mon, 12 Nov 2007 14:20:00 GMThttp://m.tkk7.com/boluobn/articles/160060.htmlhttp://m.tkk7.com/boluobn/comments/160060.htmlhttp://m.tkk7.com/boluobn/articles/160060.html#Feedback0http://m.tkk7.com/boluobn/comments/commentRss/160060.htmlhttp://m.tkk7.com/boluobn/services/trackbacks/160060.html有一DJavaScript如下Q?/p>

代码
  1. var obj = {   
  2.     prop1: "a0~`!@#$%^&*()-_+={}[]|\\:;\"',.?/",   
  3.     prop2: ['x','y'],   
  4.     prop3: {   
  5.         nestedProp1: 'abc',    
  6.         nestedProp2: 456  
  7.     }   
  8. }  

 

本文会讨论如何把一个对象{换ؓJSONq将其发送到服务器?
R輯 使用Ext.urlEncodeq行URL~码

首先我们看看Ext.urlEncode q个Ҏ(gu)Q相对应的是Ext.urlDecode解码Ҏ(gu)Q?Ext.urlEncode()不能用来处理JSONQExt.urlEncode()只是负责在HTTPq行GET、POSThӞ某?#8220;普通的” 对象转换成名U?|name/valueQ的状态。我q里?#8220;普?#8221;的意思是urlEncode只是第一层属性编码,———数l自然没有问题但内嵌的对象就不行了?举例Q?

代码
  1. Ext.urlEncode(obj) == "prop1=a0~%60!%40%23%24%25%5E%26*()-_%2B%3D%7B%7D%5B%5D%7C%5C%3A%3B%22'%2C.%3F%2F&prop2=x&prop2=y"  

* 注意属?被忽略了
* 注意Ҏ(gu)字符都被~码了(使用JS自n的encodeURIComponent()Q?

 

如果你只是想Ua地发送一些的hQ可把参数写成JavaScript原生对象的Ş式,然后用这个方法编码urlEncode发送,———这是较方便的做法?/p>

例如Q你可以在一个GETh的URL后面加上一D|本字W:

* h是这L(fng):

代码
  1. http://myurl.com?prop1=a0~%60!%40%23%24%25%5E%26*()-_%2B%3D%7B%7D%5B%5D%7C%5C%3A%3B%22'%2C.%3F%2F&prop2=x&prop2=y   

* 服务器会透过URIComponent解码成ؓQ?

 

代码
  1. prop1   a0~`!@#$%^&*()-_+={}[]|\:;"',.?/   
  2. prop2   x   
  3. prop2   y  

 

你也可以同POSTh发送这L(fng)内容Q?/p>

* h是这L(fng):

代码
  1. http://myurl.com  

 

* POST内容Q?

代码
  1. prop1=a0~%60!%40%23%24%25%5E%26*()-_%2B%3D%7B%7D%5B%5D%7C%5C%3A%3B%22'%2C.%3F%2F&prop2=x&prop2=y   

* 服务器得到的l果是和GETh的内Ҏ(gu)异的?

 

q一切还利Q但说到要发送和接受JSONQ该怎么办呢Q接下来再看Q?
R輯 使用Ext.encode~码JSON

Ext.encode() Q其对应的解码方法ؓExt.decodeQ{换一个复制的对象ZDJSON字符举例Q?/p>

代码
  1. Ext.encode(obj) == '{"prop1":"a0~`!@#$%^&*()-_+={}[]|\\:;\"\',.?/","prop2":["x","y"],"prop3":{"nestedProp1":"abc","nestedProp2":456}}'   

* 注意内嵌对象的属性现在被包含q去?

 

刚才是我们{换一个简单的对象到名U?|name/valueQ的状态,现在的情况将有所不同Q此时的对象已经被{换到Q序列化Q一D参数。具体的作用是,以名U?|name/valueQ的形式Q发送到服务器解析。如果只是发送一个JSON字符Ԍ可认个就是json参数?/p>

要将JSON转换成ؓ可GET/POST适合发送的名称/|name/valueQ状态,你可以额外地其~码Q?

代码
  1. encodeURIComponent(Ext.encode(obj)) == "%7B%22prop1%22%3A%22a0~%60!%40%23%24%25%5E%26*()-_%2B%3D%7B%7D%5B%5D%7C%5C%5C%3A%3B%5C%22'%2C.%3F%2F%22%2C%22prop2%22%3A%5B%22x%22%2C%22y%22%5D%2C%22prop3%22%3A%7B%22nestedProp1%22%3A%22abc%22%2C%22nestedProp2%22%3A456%7D%7D"  

创徏一个GET的请求如下:
代码
  1. "http://url.com?json=" + encodeURIComponent(Ext.encode(obj))   

或是POSTh也行Q?

 

代码
  1. "json=" + encodeURIComponent(Ext.encode(obj))  

 

urlEncode()Ҏ(gu)也是可以Q?

代码
  1. Ext.urlEncode({ json: Ext.encode(obj)}) == "json=%7B%22prop1%22%3A%22a0~%60!%40%23%24%25%5E%26*()-_%2B%3D%7B%7D%5B%5D%7C%5C%5C%3A%3B%5C%22'%2C.%3F%2F%22%2C%22prop2%22%3A%5B%22x%22%2C%22y%22%5D%2C%22prop3%22%3A%7B%22nestedProp1%22%3A%22abc%22%2C%22nestedProp2%22%3A456%7D%7D"  

q样便可以通过GET/POST发送。至于另一边的服务端,会透过URIComponent解码q段参数Q?

 

代码
  1. {"prop1":"a0~`!@#$%^&*()-_+={}[]|\\:;\"',.?/","prop2":["x","y"],"prop3":{"nestedProp1":"abc","nestedProp2":456}}   

来访问JSON已解码的数据?
R輯 使用Ext.Ajax.request发送JSON

 

在EXT 1.1,你可以轻村֜使用Ext.Ajax.request()Ҏ(gu)来创Z个典型AJAX的请求。该Ҏ(gu)允许传入一个配|项的对象,x可包含其它类型的内容Q作求的参数的用途,下面引用API的介l:

Q原文)params {Object/String/Function} (Optional) An object containing properties which are used as parameters to the request, a url encoded string or a function to call to get either.

Q中文)params {Object/String/Function} (可选项) 包含h参数的对象,以对象的属性Ş式出玎ͼ一D可url~码的字W串Q或者是可返回以上两者的函数?/p>

对于传入的是objectcdQ?Ext.Ajax.request会调用Ext.urlEncode()其转换为名U?|name/valueQ的状态(通常情况忽略内嵌的对象)?/p>

代码
  1. var req = Ext.Ajax.request({   
  2.     url: "/ws/search.pl",   
  3.     params: obj,   
  4.     method: 'GET',   
  5.     disableCaching: false  
  6. })  

 

h是这L(fng)Q?/p>

代码
  1. /ws/search.pl?prop1=a0~%60!%40%23%24%25%5E%26*()-_%2B%3D%7B%7D%5B%5D%7C%5C%3A%3B%22'%2C.%3F%2F&prop2=x&prop2=y   

服务端解析ؓQ?

 

代码
  1. prop1   a0~`!@#$%^&*()-_+={}[]|\:;"',.?/   
  2. prop2   x   
  3. prop2   y  

 

* 如不止disableCachingQExt会加上唯一的_dc参数以消除缓册Ӏ?
* 每次送出的数据都是经qExt.urlEncode()Q很明显是没有发送完整的JSON,只是一q串的名U?|name/valueQ的状态?

如果使用POST的方法,q程也是相同Q区别是名称/|name/valueQ的状态是攑֜POST BOBY内发送?/p>

要把JSON发送到服务器,我们需要用Ext.encode()Ҏ(gu)转换数据对象到文本格式的JSON?Ext.Ajax.request()允许传入一D可URL~码的字W串Q所以你既可以用 encodeURIComponent()~码参数Q亦可直接是一个简单的对象Q让Ext.Ajax.request()Z~码Q?/p>

代码
  1. var req = Ext.Ajax.request({   
  2.     url: "/ws/search.pl",   
  3.     params: {json: Ext.encode(obj)},   
  4.     disableCaching: false  
  5. })  

 

相类似地Q服务端会解析ؓQ?/p>

代码
  1. {"prop1":"a0~`!@#$%^&*()-_+={}[]|\\:;\"',.?/","prop2":["x","y"],"prop3":{"nestedProp1":"abc","nestedProp2":456}}  

 

q样我们便可以访问JSON已解码的数据了?/p>

菠萝 2007-11-12 22:20 发表评论
]]>
中文化问??http://m.tkk7.com/boluobn/articles/160059.html菠萝菠萝Mon, 12 Nov 2007 14:16:00 GMThttp://m.tkk7.com/boluobn/articles/160059.htmlhttp://m.tkk7.com/boluobn/comments/160059.htmlhttp://m.tkk7.com/boluobn/articles/160059.html#Feedback0http://m.tkk7.com/boluobn/comments/commentRss/160059.htmlhttp://m.tkk7.com/boluobn/services/trackbacks/160059.htmlq两个问题,解答如下Q?/p>

1、中文化问题Q在 ext-all.js 后面Q挂?ext-lang-zh_CN.js 卛_Q如Q?

代码
  1. <script type="text/javascript" src="<%=contextPath%>/public/js/ext-base.js"></script>  
  2. <script type="text/javascript" src="<%=contextPath%>/public/js/ext-all.js"></script>  
  3. <script type="text/javascript" src="<%=contextPath%>/public/js/ext-lang-zh_CN.js"></script>  

 

Q?/p>

菠萝 2007-11-12 22:16 发表评论
]]>
学习一下EXT 作了些笔?/title><link>http://m.tkk7.com/boluobn/articles/153683.html</link><dc:creator>菠萝</dc:creator><author>菠萝</author><pubDate>Wed, 17 Oct 2007 13:34:00 GMT</pubDate><guid>http://m.tkk7.com/boluobn/articles/153683.html</guid><wfw:comment>http://m.tkk7.com/boluobn/comments/153683.html</wfw:comment><comments>http://m.tkk7.com/boluobn/articles/153683.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://m.tkk7.com/boluobn/comments/commentRss/153683.html</wfw:commentRss><trackback:ping>http://m.tkk7.com/boluobn/services/trackbacks/153683.html</trackback:ping><description><![CDATA[     摘要: 文载入l束 初始化dom Ext.onReady(function(){         //初始化以及应用代?}); 弹出警告对话?Ext.MessageBox.alert("Warning", "This example is not done and results may vary."); 表单 <form id="...  <a href='http://m.tkk7.com/boluobn/articles/153683.html'>阅读全文</a><img src ="http://m.tkk7.com/boluobn/aggbug/153683.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://m.tkk7.com/boluobn/" target="_blank">菠萝</a> 2007-10-17 21:34 <a href="http://m.tkk7.com/boluobn/articles/153683.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Ext布局cȝ介绍与?/title><link>http://m.tkk7.com/boluobn/articles/153680.html</link><dc:creator>菠萝</dc:creator><author>菠萝</author><pubDate>Wed, 17 Oct 2007 13:28:00 GMT</pubDate><guid>http://m.tkk7.com/boluobn/articles/153680.html</guid><wfw:comment>http://m.tkk7.com/boluobn/comments/153680.html</wfw:comment><comments>http://m.tkk7.com/boluobn/articles/153680.html#Feedback</comments><slash:comments>2</slash:comments><wfw:commentRss>http://m.tkk7.com/boluobn/comments/commentRss/153680.html</wfw:commentRss><trackback:ping>http://m.tkk7.com/boluobn/services/trackbacks/153680.html</trackback:ping><description><![CDATA[     摘要: 在WEB应用的开发中Q应用界面的布局设计是一很重要的内宏V在EXT中,可以通过BorderLayout与NestedLayoutPanel很方便的设计出各U的布局。本文章的主要内容主要是介绍如何通过BorderLayout、NestedLayoutPanel以及各种面板设计面布局?  <!--[if !supportLists]-->1.  &n...  <a href='http://m.tkk7.com/boluobn/articles/153680.html'>阅读全文</a><img src ="http://m.tkk7.com/boluobn/aggbug/153680.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://m.tkk7.com/boluobn/" target="_blank">菠萝</a> 2007-10-17 21:28 <a href="http://m.tkk7.com/boluobn/articles/153680.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>一个用ext做的d面http://m.tkk7.com/boluobn/articles/153223.html菠萝菠萝Tue, 16 Oct 2007 04:37:00 GMThttp://m.tkk7.com/boluobn/articles/153223.htmlhttp://m.tkk7.com/boluobn/comments/153223.htmlhttp://m.tkk7.com/boluobn/articles/153223.html#Feedback0http://m.tkk7.com/boluobn/comments/commentRss/153223.htmlhttp://m.tkk7.com/boluobn/services/trackbacks/153223.html最q在xextQ感觉ext比dodjo的前景好Q在|上扑ֈ一个用ext做的d?http://ondemand.aicproperties.com/

http://ondemand.aicproperties.com/

参照q个可以修改己想要的d面Q我是参照q个面Q修改了pȝ的登录界?/p>

菠萝 2007-10-16 12:37 发表评论
]]>
学习EXTW一?EXT?/title><link>http://m.tkk7.com/boluobn/articles/135061.html</link><dc:creator>菠萝</dc:creator><author>菠萝</author><pubDate>Tue, 07 Aug 2007 12:24:00 GMT</pubDate><guid>http://m.tkk7.com/boluobn/articles/135061.html</guid><wfw:comment>http://m.tkk7.com/boluobn/comments/135061.html</wfw:comment><comments>http://m.tkk7.com/boluobn/articles/135061.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://m.tkk7.com/boluobn/comments/commentRss/135061.html</wfw:commentRss><trackback:ping>http://m.tkk7.com/boluobn/services/trackbacks/135061.html</trackback:ping><description><![CDATA[<p>无论你是Ext库的新手Q抑或是想了解Ext的hQ本文章的内容都适合你。本文将单地介绍Ext的几个基本概念,和如何快速地做出一个动态的面q运行v来,假设读者已具备了一些JavaScriptl验和初U了解HTML Dom。否则的话,请从阅读<a target=_blank>初学JavaScript资源</a>开始?</p> <h2>下蝲Ext</h2> <p>如果你未曾下载过Q那应从q里下蝲最新版本的Ext <a target=_blank>http://extjs.com/downloads</a>?/p> <p>针对你的下蝲需求,有几个不同的Ҏ(gu)选项。通常圎ͼ最E_的版本,是较多h的选择。下载解包后Q那个example文g夹便是一个探索Ext的好地方Q?/p> <h2>开始!</h2> <p>我们用ExtQ来完成一些JavaScriptd?/p> <p>W一步要做的是,下蝲本教E的<a target=_blank>CZ文g</a>。Zip文g包括三个文gQ?strong>ExtStart.html</strong>, <strong>ExtStart.js</strong>?strong>ExtStart.css</strong>。解包这三个文g到Ext的安装目录中Q例如,Ext是在“C:\code\Ext\v1.0”中,那应该在"v1.0"里面新徏目录“tutorial”。双?strong>ExtStart.htm</strong>Q接着你的览器打开启动面Q应该会有一条消息告诉你配置已完毕。如果是一个Javascript错误Q请按照面上的指引操作?/p> <p>在你常用的IDE中或文本~辑器中Q打开ExtStart.js看看Q?/p> <p>Ext.onReady可能是你接触的第一个方法。这个方法是指当前DOM加蝲完毕后,保证面内的所有元素能被Script引用QreferenceQ。你可删除alert()那行Q加入一些实际用途的代码试试Q?/p> <pre>Ext.onReady(function() { alert("Congratulations! You have Ext configured correctly!"); }); </pre> <h2>ElementQExt的核?/h2> <p>大多数的JavaScript操作都需要获取页面上的某个元素(referenceQ?好让你来做有的事情。传l的JavaScriptҎ(gu)Q是通过ID获取Dom节点的:</p> <pre>var myDiv = document.getElementById('myDiv');</pre> <p>q毫无问题,不过q样单单q回一个对象(DOM节点Q,用v来ƈ不是太强大和好用。ؓ了要用那节点q点事情Q你会要写不少自定义的代码Q另外,对于不同cd览器之间的差异Q要你处理v来可真头大了?/p> <p>q入<a target=_blank>Ext.element</a>对象。元素(elementQ的的确是Ext的心脏地带,--无论是访问元素(elementsQ还是完成一些动作,都要涉及它。Element的API是整个Ext库的基础Q如果你旉不多Q只想了解Ext中的一个类的话QElement一定是首选!</p> <p>由ID获取一个Ext Element如下Q首ExtStart.htm包含一个divQID名字?#8220;myDiv”Q然后,在ExtStart.js中加入下列语句)Q?/p> <pre>Ext.onReady(function() {var myDiv = Ext.get('myDiv');});</pre> <p>再回头看看Element对象Q发C么有的东东呢?</p> <ul> <li>Element包含了常见的DOMҎ(gu)和属性,提供一个快L(fng)、统一的、跨览器的接口Q若使用Element.dom的话Q就可以直接讉K底层DOM的节炏V)Q? <li>Element.get()Ҏ(gu)内置~存处理QCache)Q多ơ访问同一对象效率上有极大优势Q? <li>内置常用的DOM节点的动作,q且是跨览器的定位的位|、大、动甅R拖攄{(add/remove CSS classes, add/remove event handlers, positioning, sizing, animation, drag/dropQ?</li> </ul> <p>q意味着你可用最的代码来做各种各样的事情,q里仅仅是一个简单的例子Q完整的列表?a target=_blank>ElementAPI</a>中)?/p> <p>l箋在ExtStart.js中,在刚才我们获取好myDiv的位|中加入Q?/p> <pre>myDiv.highlight(); //黄色高亮昄然后渐退 myDiv.addClass('red'); // d自定义CSSc?(在ExtStart.css定义) myDiv.center(); //在视图中元素居? myDiv.setOpacity(.25); // 使元素半透明 </pre> <h2>获取多个DOM的节?/h2> <p>通常情况下,不能由ID获取多个DOM的节点,有可能因为没讄ID,或者你不知道ID,又或者直接用ID方式引用有太多元素了。这U情况下Q你会不用ID来作取元素的依据Q可能会用属性(attributeQ或CSS Classname代替。基于以上的原因QExt引入了一个功能异常强大的Dom Selector库,叫做<a target=_blank>DomQuery</a>?/p> <p>DomQuery可作为单独的库用,但常用于ExtQ你可以在上下文环境中(ContextQ获取多个元素,然后通过Element接口调用。幸q的是,Element对象本n便有<a target=_blank>Element.selcect</a>的方法来实现查询Q即内部调用DomQuery选取元素。这个简单的例子中,ExtStart.htm包含若干D落Q?/p> <p>标签Q,没有一个是有ID的,而你惌村֜通过一ơ操作马上获取每一D,全体执行它们的动作,可以q样做:</p> <pre>// 每段高亮昄 Ext.select('p').highlight(); </pre> <p>DomQuery的选取参数是一D较长的数组Q其中包括W3C CSS3 Dom选取器、基本XPath、HTML属性和更多Q请参阅<a target=_blank>DomQuery API文</a>以了解这功能强大的库的细节?/p> <h2>响应事g</h2> <p>到这范例为止Q我们所写的代码都是攑֜onReady中,卛_面加蝲后M立即执行Q功能较单一——这L(fng)话,你便知道Q如何响应某个动作或事g来执行你希望做的事情Q做法是Q先分配一个functionQ再定义一个event handler事g处理器来响应。我们由q个单的范例开始,打开ExtStart.htmQ编辑下列的代码Q?/p> <pre>Ext.onReady(function() { Ext.get('myButton').on('click', function(){ alert("You clicked the button"); }); }); </pre> <p>加蝲好页面,代码依然会执行,不过区别是,包含alert()的function是已定义好的Q但它不会立卛_被执行,是分配到按钮的单M件中。用显的文字解释,是Q获取ID?myDottom'元素的引用,监听M发生元素被单ȝ情况Qƈ分配一个function,以准备Q何单d素的情况?/p> <p>正\来说QElement.select也能做同L(fng)事情Q即作用在获取一l元素上。下一例中Q演CZ面中的某一D落被单dQ便有弹出窗口:</p> <pre>Ext.onReady(function() { Ext.select('p').on('click', function() { alert("You clicked a paragraph"); }); }); </pre> <p>q两个例子中Q事件处理的function均是单几句,没有函数的名Uͼq种cd函数UCؓ“匿名函数Qanonymous functionQ?#8221;Q即是没有名的的函数。你也可以分配一个有名字的event handler,q对于代码的重用或多个事件很有用。下一例等效于上一例:</p> <pre>Ext.onReady(function() { var paragraphClicked = function() { alert("You clicked a paragraph"); } Ext.select('p').on('click', paragraphClicked); }); </pre> <p>到目前ؓ止,我们已经知道如何执行某个动作。但当事件触发时Q我们如何得知这个event handler执行时是作用在哪一个特定的元素上呢Q要明确q一炚w常简单,<a target=_blank>Element.on</a>Ҏ(gu)传入到even handler的function中(我们q里先讨论第一个参敎ͼ不过你应该浏览API文档以了解even handler更多的细节)。在我们之前的例子中Qfunction是忽略这些参数的Q到q里可有许的改变,——我们在功能上提供了更深层次的控制。必d说明的是Q这实际上是Ext的事件对象(event objectQ?一个跨览器和拥有更多控制的事件。例如,可以用下列的语句Q恢复这个事件的指定的DOM节点Q?br></p> <pre>Ext.onReady(function() { var paragraphClicked = function(e) { Ext.get(e.target).highlight(); } Ext.select('p').on('click', paragraphClicked); }); </pre> <p>注意指定的是DOM节点Q所以我们首先将其恢复成为适当的元素,然后执行Ʋ完成的事gQ这个例子中Q我们看见段落是高亮昄的?</p> <img src ="http://m.tkk7.com/boluobn/aggbug/135061.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://m.tkk7.com/boluobn/" target="_blank">菠萝</a> 2007-08-07 20:24 <a href="http://m.tkk7.com/boluobn/articles/135061.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>学习EXTW三?EXT:Menulghttp://m.tkk7.com/boluobn/articles/135058.html菠萝菠萝Tue, 07 Aug 2007 12:22:00 GMThttp://m.tkk7.com/boluobn/articles/135058.htmlhttp://m.tkk7.com/boluobn/comments/135058.htmlhttp://m.tkk7.com/boluobn/articles/135058.html#Feedback0http://m.tkk7.com/boluobn/comments/commentRss/135058.htmlhttp://m.tkk7.com/boluobn/services/trackbacks/135058.html 讲讲如何使用Ext菜单器g

q篇教程中,我们学习用Ext的菜单器ӞMenu Widgets)。假设读者已l阅读过Ext介一文,q懂得一些Ext的基本相关知识。菜单器件是Ext库中较迟实现的器件。它由几个类联合构成Q得创Z个菜单只需若干代码块(Block of codeQ?/p>

开始!

W一步要做的是,下蝲本教E的CZ文g。Zip文g包括三个文gQ?strong>ExtMenu.html,?strong>ExtMenu.js?strong>ExtMenu.css?/strong>?strong>list-items.gif。解包这四个文g到Ext的安装目录中Q例如,Ext是在“C:\code\Ext\v1.0”中,那应该在"v1.0"里面新徏目录“menututorial”。双?strong>ExtMenu.htmQ接着你的览器打开启动面Q应该会有一条消息告诉你配置已完毕。如果是一个Javascript错误Q请按照面上的指引操作?/p>

在你常用的IDE中或文本~辑器中Q打开ExtMenu.js看看Q?/p>

Ext.onReady(function() {
alert("You have Ext configured correctly! We are now ready to do some Ext Menu Magic!");
});

在Ext的介l中Q我们讨使用Ext的原因和Ext.onReady()函数的功能?/p>


创徏易的菜单

先看看怎么做一个基本的菜单Q然后再讨论代码中的各个lg和知识点。加入下列代码到onReady函数?

var menu = new Ext.menu.Menu({
id: 'basicMenu',
items: [{
text: 'An item',
handler: clickHandler
},
new Ext.menu.Item({
text: 'Another item',
handler: clickHandler
}),
'-',
new Ext.menu.CheckItem({
text: 'A check item',
checkHandler: checkHandler
}),
new Ext.menu.CheckItem({
text: 'Another check item',
checkHandler: checkHandler
})
]
});
var tb = new Ext.Toolbar('toolbar', [{
text:'Our first Menu',
menu: menu  // 分配menu到按?
}
]);
function clickHandler() {
alert('Clicked on a menu item');
}
function checkHandler() {
alert('Checked a menu item');
}

OK 仔细看看q里的代码,首先实例化一个MenucMؓ变量“menu”。然后Menu的构建函数接受一串的Object Literal作ؓ参数Q在先前的Ext教程中我们已l讨对ObjectLiteralq行了解。当前的ObjectLiteral包含了我们菜单中想要的属性。第一个属性是我们分配的IDQ稍后我们可用ID来获取Menu的引用?

 


各种Item的类?/h2>

属?#8220;items”可能是最重要的属性当中的一个。留意一下语法其实我们是一个数l作为|value)传到属性中厅R数l里的数据就是我们想要在菜单中出现的每一V每本例中我们放了六个菜单项Q但何解每项的语法(SyntaxQ都不尽相同呢?W一Ҏ(gu)一串Object LiteralQ包含一l我们可配置的name/value。Ext的底层库会ؓq串Object Literal按其配置默认地创建item对象。接着W二Ҏ(gu)Item对象本nQ后面跟着分隔W,最后两个是单选框V整个过E演CZExt Widget如何动态的q行。下例各可填入到数l中Q?/p>

{text: 'Foo'}                       // Ext 转换q个配置对象到menu item
'Straight Text'                     //文本或原始html (U文?
'-'                                 // 创徏分隔W?
new Ext.menu.Item({text: 'Foo'})    // 创徏一个标准item (同{text: 'Foo'})
new Ext.menu.CheckItem()            // 创徏单选框item
new Ext.menu.DateItem()             // 创徏menu内置的日历控?
new Ext.menu.ColorItem()            //创徏一个颜色采集器
new Ext.menu.BaseItem(document.getElementById('my-div')) //允许你加入Q何元?

Item属?/h2>

Item接受什么类型的属性呢Q本例中我们使用了这两属性:

text: 'An item',
handler: clickHandler

W一个是Item的文本。第二个是当用户单击一单击Item所触发的事件处理函敎ͼevent handler functionQ。本例中我们函数clickHandler()和checkHandler()定义在代码的最后。作为演C用途,q仅仅是用alert()通知你有一个单ȝ消息?br>其它有用的属性是Q?/p>

cls: 'a-class-name'  ,       // 为标准Item手动讄样式和图标ICON
icon: 'url',                 // 如不想用CSS,可直接设|图标的URL
group: 'name of group',      //只适用多选项Q保证只有一被选中

完整的item属性列表在Menu Item文档中?/p>

在UI中摆放菜?/h2>

So,创徏好的Menu对象已经有两个基本的item了,然而我们怎么把它们摆攑ֈ面中呢?在UI中一个menu可以分配到多个位|(同一个对象,不同位置多次使用Q,q正是Ext如此强大的原因:每一个器ӞwidgetQ切?#8220;一块一?#8221;的类Q来构徏整个面向对象的动态结构(StructureQ。这意味着menu可用于不同的场合。我们可menu攑ֈ有按钮的toolbar中,或用面中的一个按钮来展开menuQ甚臛_在Ext的其它器件中QwidgetsQ用menu作ؓ上下文菜单(Context MenuQ?/p>

本例中分配一个menu到toolbar中:

var tb = new Ext.Toolbar('toolbar', [{
text:'Our first Menu',
menu: menu  // 分配menu到toolbar
}
]);

Ext.Toolbar构徏函数接受两个参数Q第一个是指定toolbar的容器(contrainerQ;W二个参数是包含全部按钮的数l。这?我们只用一个按?正如所见,按钮实质上是一串由数组l成的Object Literal,同时q个Object Litetal亦包含了不同的属性。下面是一l按钮对象的Object Litetal属性:

cls: 'a-class-name'  ,      //手动讄样式和图标ICON
icon: 'url',                // 如不想用CSS,可直接设|图标的URL
text:'Our first Menu',      // 按钮提示之文?
menu: menu                  // 可以是menu之id或配|对?

Menu的分配方式:

刚才谈到如何分配Menu到工h中(toolbarQ,l而亦讨论menu分配的不同方式,看看有关的细节是怎样的。So,因ؓmenu属性可以以不同方式地分配,x可以赋予一个menu对象Q或是已l徏好的menuIDQ或直接是一个menu config对象。你应该有机会就试一下以多种方式创徏menuQ因为类似的方式Ҏ(gu)在Ext的Widgets随处可见。下面的代码演示了如何用不同的方法来做出跟范例一L(fng)效果Q唯一相同的就是menu对象的config。菜单中包括两个子菜单、一个DataItem容器、一个ColorItem容器。另外注意event handing函数需两个参数来获取事件更多的信息和知道哪个item被单M。可以的话,把下面的代码也加入到onReady函数中,亲n体验一下:

var dateMenu = new Ext.menu.DateMenu({
handler : function(datepicker, date){
alert('Date Selected', 'You chose: '+ date.format('M j, Y'));
}
});
var colorMenu = new Ext.menu.Menu({
id: 'colorMenu', // the menu's id we use later to assign as submenu
items: [
new Ext.menu.ColorItem({
selectHandler: function(colorpicker, color){
alert('Color Selected', 'You chose: ' + color);
}
})
]
});
var tb = new Ext.Toolbar('toolbar', [{
text:'Our first Menu',
menu: {
id: 'basicMenu',
items: [{
text: 'An item',
handler: clickHandler
}, {
text: 'Another item',
handler: clickHandler
},
'-',
new Ext.menu.CheckItem({
text: 'A check item',
checkHandler: checkHandler
}),
new Ext.menu.CheckItem({
text: 'Another check item',
checkHandler: checkHandler
}),
'-', {
text: 'DateMenu as submenu',
menu: dateMenu, // assign the dateMenu we created above by variable reference,
handler: date
}, {
text: 'Submenu with ColorItem',
menu: 'colorMenu'    // we assign the submenu containing a ColorItem using it's id
}
]
}
}
]);
function clickHandler(item, e) {
alert('Clicked on the menu item: ' + item.text);
}
function checkHandler(item, e) {
alert('Checked the item: ' + item.text);
}

注意Q?/strong>留意几种不同的方法加入子菜单Q还有even handing函数和Coloritem、DataMenu匿名函数之间的区别?/p>


l一l?/h2>

Ok我们用上q的Ҏ(gu)Q创Ztoolbar和menuQ看h应该是这L(fng)Q?/p>

上文提及menu可摆攑֜UI的Q何位|,q里ؓ你演Cmenu如何与Toolbars、MeneuButtons、Context Menus's配合工作Q包括一些有用的Ҏ(gu)和动态添加的功能?/p> MenuButton

new Ext.MenuButton('menubutton', {text:'Menu Button 1', menu: dateMenu});

动态添加菜单按钮到Toolbar

q条Toolbar有两个按钮。一个分隔符Q和一个纯图标的按钮(附QuicktipsQ。你可尝试这样做Q把zip文g?gif加入

Ext.QuickTips.init();
tb.add('-', {
icon: 'list-items.gif', //图标可单行显C?
cls: 'x-btn-icon',      // U图?
tooltip: 'Quick Tips
提示文字' });

更方便的?/h2>

一些代码片D,有助你提高效率,留意注释Q?

// Menus更多的API内容
// 动?增、减元素
menu.addSeparator(); //动态加入分隔符
var item = menu.add({
text: 'Dynamically added Item'
});
// items 完整支持Observable API
item.on('click', onItemClick);
// items can easily be looked up
menu.add({
text: 'Disabled Item',
id: 'disableMe'  // <-- 讄ID便于查找lookup
// disabled: true   <-- 先不disabled 而采用下面的方式
});
// ?id ?index讉K
menu.items.get('disableMe').disable();

下一步是

现在你已l了解菜单组件是如何工作了。下面的资源有助(zhn)进一步更深入学习菜单Q?/p>

菠萝 2007-08-07 20:22 发表评论
]]>学习EXTW二?EXT介(二)http://m.tkk7.com/boluobn/articles/135060.html菠萝菠萝Tue, 07 Aug 2007 12:22:00 GMThttp://m.tkk7.com/boluobn/articles/135060.htmlhttp://m.tkk7.com/boluobn/comments/135060.htmlhttp://m.tkk7.com/boluobn/articles/135060.html#Feedback0http://m.tkk7.com/boluobn/comments/commentRss/135060.htmlhttp://m.tkk7.com/boluobn/services/trackbacks/135060.html使用Widgets

(Widget原意?#8220;器?#8221;Q现指页面中UI控g)

除了我们已经讨论q的核心JavaScript库,现在的Ext亦包括了一pd的最前端的JavaScirptUIlg库。文本以一个最常用的widgetZ子,作简单的介绍?/p>

MessageBox

比v略ؓ沉闷?#8220;HelloWolrd”消息H口Q我们做许变化Q前面我们写的代码是Q单L个段落便会高亮显C,现在是单L落,在消息窗口中昄D落内容出来?br>在上面的paragraphClicked的function中,这行代码:

Ext.get(e.target).highlight();

替换为:

var paragraph = Ext.get(e.target);
paragraph.highlight();
Ext.MessageBox.show({
title: 'Paragraph Clicked',
msg: paragraph.dom.innerHTML,
width:400,
buttons: Ext.MessageBox.OK,
animEl: paragraph
});

q里有些新的概念讨论一下。在W一行中我们创徏了一个局部变量(Local VariableQ来保存某个元素的引用,卌单击的那个DOM节点Q本例中Q我们LD落paragrah,事因我们已经定义该事件与<p>标签发生兌的了Q。ؓ什么要q样做呢Q嗯...观察上面的代码,我们需要引用同一元素来高亮显C,在MessageBox中也是引用同一元素作ؓ参数使用?br>一般来_多次重复使用同一|ValueQ或对象Q是一个不好的方式Q所以,作ؓ一个好的OOP开发者,应该是将其分配到一个局部变量中Q反复用这变量Q?/p>

现在Q观察MessageBox的调用,准备作ؓ阐述新概늚演示用。乍一看,q像一q串的参C入到Ҏ(gu)中,但仔l看Q这是一个非常特别的语法。实际上Q传入到MessageBox.show的只有一个参敎ͼ一个Object literal,包含一l属性和属性倹{在Javascript中,Object Literal是动态的Q你可在M时候用{和}创徏一个典型的对象(object)。其中的字符׃pd的name/valuel成的属性,属性的格式是[property name]:[property value]。在整个Ext中,你将会经帔R到这U模式的语法Q因此你应该消耗掉q知识!
使用Object Literal的原因是什么呢Q主要的原因?#8220;韧性(flexibilityQ?Q随时可新增、删除属性,亦可不管序地插入。而方法不需要改变。这也是多个参数的情况下Qؓ最l开发者带来不的方便Q本例中的MessageBox.show())。例如,我们说这儿的foo.actionҎ(gu)Q有四个参数Q而只有一个是你必M入的。本例中Q你惛_中的代码可能会是q样的foo.action(null, null, null, 'hello').,若果那方法用Object Literal来写Q却是这P foo.action({ param4: 'hello' })Q这更易用和易读?/p>

Gird

Gird是Ext中h们最惛_睹ؓ快的Widgets之一Q也是最行之一。好Q让我们看看怎么L地创Z个Girdq运行。用下列代码替换ExtStart.js中全部语句:

Ext.onReady(function() {
var myData = [
['Apple',29.89,0.24,0.81,'9/1 12:00am'],
['Ext',83.81,0.28,0.34,'9/12 12:00am'],
['Google',71.72,0.02,0.03,'10/1 12:00am'],
['Microsoft',52.55,0.01,0.02,'7/4 12:00am'],
['Yahoo!',29.01,0.42,1.47,'5/22 12:00am']
];
var ds = new Ext.data.Store({
proxy: new Ext.data.MemoryProxy(myData),
reader: new Ext.data.ArrayReader({id: 0}, [
{name: 'company'},
{name: 'price', type: 'float'},
{name: 'change', type: 'float'},
{name: 'pctChange', type: 'float'},
{name: 'lastChange', type: 'date', dateFormat: 'n/j h:ia'}
])
});
ds.load();
var colModel = new Ext.grid.ColumnModel([
{header: "Company", width: 120, sortable: true, dataIndex: 'company'},
{header: "Price", width: 90, sortable: true, dataIndex: 'price'},
{header: "Change", width: 90, sortable: true, dataIndex: 'change'},
{header: "% Change", width: 90, sortable: true, dataIndex: 'pctChange'},
{header: "Last Updated", width: 120, sortable: true,
renderer: Ext.util.Format.dateRenderer('m/d/Y'), dataIndex: 'lastChange'}
]);
var grid = new Ext.grid.Grid('grid-example', {ds: ds, cm: colModel});
grid.render();
grid.getSelectionModel().selectFirstRow();
});

q看上去很复杂,但实际上加v来,只有七行代码。第一行创建数lƈ作ؓ数据源。实际案例中Q你很可能从数据库、或者WebService那里得到动态的数据。接着Q我们创建ƈ加蝲data storeQ?data store会告诉Ext的底层库接手处理和格式化q些数据。接着Q我们定义一个column模型Q用来轻村֜调配Gird的每一列参数。最后我们生成这个Gird,传入data store和column模型两个对象Q进行渲染ƈ选好W一行。不是太困难吧?如果一切顺利,搞掂之后你会看到像这L(fng)Q?

当然Q你可能对这D代码的某些l节Qƈ不完全掌握其中的含义Q像MemoryProxyI竟是什么?Q但先不要紧Q这个例子的目的是告诉你Q用量的代码,创徏一个富界面的多功能的UIlg而已——这是完全可能的Q更多细节的内容Q留l读者你自己学习吧。这儿有许多学习Grid的资源?a target=_blank>Ext Grid教程?a target=_blank>交叉Gird演示?a target=_blank>Gird API文?

q有更多?.

q只是冰׃角。还有一打的UI Widgets可以供调用,?layouts, tabs, menus, toolbars, dialogs, tree view{等。请参阅API文?a >范例演示?

使用Ajax

在弄好一些页面后Q你已经懂得在页面和脚本之间的控制原理(interactQ。接下来Q你想知道的是,怎样与后台服务器Qremote serverQ交换数据,常见的是从数据库加蝲数据QloadQ或是保存数据(saveQ到数据库中。通过JavaScript异步无刷C换数据的q种方式Q就是所谓的Ajax。Ext内徏卓越的Ajax支持Q例如,一个普遍的用户操作是Q异步发送一些东西到服务器,然后QUI元素Ҏ(gu)回应QResponseQ作出更新。这是一个包含text input的表单,一个div用于昄消息Q注意,你可以在ExtStart.html中加入下列代码,但这必须要访问服务器Q:

<div id="msg" style="visibility: hidden"></div>
Name: <input type="text" id="name" /><br />
<input type="button" id="oKButton" value="OK" />

接着Q我们加入这些处理交换数据的JavaScript代码到文件ExtStart.js?用下面的代码覆盖)Q?/p>

Ext.onReady(function(){
Ext.get('oKButton').on('click', function(){
var msg = Ext.get("msg");
msg.load({
url: [server url], //换成你的URL
params: "name=" + Ext.get('name').dom.value,
text: "Updating..."
});
msg.show();
});
});

q种模式看v来已l比较熟(zhn)了吧!先获取按钮元素,加入单击事g的监听。在事g处理器中Qevent handlerQ,我们使用一个负责处理Ajaxh、接受响应(ResponseQ和更新另一个元素的Ext内徏c,UCUpdateManager。UpdateManager可以直接使用Q或者和我们现在的做法一P通过Element的loadҎ(gu)来访问(本例中该元素?#8220;msg“的divQ。当使用Element.loadҎ(gu)Q请求(request)会被加工处理后发送,{待服务器的响应QResponseQ,来自动替换元素的innerHTML。简单传入服务器url地址Q加上字W串参数Q便可以处理q个hQ本例中Q参数值来?#8220;name”元素的value),而text值就是请求发送时提示的文本,完毕后显C那个msg的divQ因为开始时默认隐藏Q。当Ӟ和大多数Extlg一PUpdateManager有许多的参数可选,不同的Ajaxh有不同的Ҏ(gu)。而这里仅演示最单的那种?/p>

PHP
<? if(isset($_GET['name'])) {
echo 'From Server: '.$_GET['name'];
}
?>
ASP.Net
protected void Page_Load(object sender, EventArgs e)
{
if (Request["name"] != null)
{
Response.Write("From Server: " + Request["name"]);
Response.End();
}
}
Cold Fusion
<cfif StructKeyExists(url, "name")>
<cfoutput>From Server: #url.name#</cfoutput>
</cfif>

最后一个关于Ajax的谜题就是,服务器实际处理请求和q回QResposneQ的具体q程。这个过E会是一个服务端面Q一个ServletQ一个Http处理器,一个WebService,甚至是Perl或CGI脚本Q即M一个服务器都可以处理httph。无法预料的是,服务器返回什么是服务器的事情Q无法给一个标准的例子来覆盖所有的可能性?q段代码输出刚才我们传入'name'的那个值到客户端,卛_送什么,q回什么)?/p>

使用Ajax的真正挑战,是需l过适当处理q的手工代码Qƈ相应格式化ؓ服务端可用接受的数据l构。有几种格式供h们选择Q最常用为JSON/XML)。正因Ext是一U与服务器中立的语言Q得其它特定语a的库亦可用于Ext处理Ajax服务。只要页面接受到l果是合适的数据格式QExtl不会过问服务器的事情!要全面讨个问题,已超出本文的范围。推荐正在用Ajax的?zhn)Q深入阅?a target=_blank>Ext Ajax教程?/p>

菠萝 2007-08-07 20:22 发表评论
]]>
学习EXTW五?-Gridlg的简易分?/title><link>http://m.tkk7.com/boluobn/articles/135056.html</link><dc:creator>菠萝</dc:creator><author>菠萝</author><pubDate>Tue, 07 Aug 2007 12:21:00 GMT</pubDate><guid>http://m.tkk7.com/boluobn/articles/135056.html</guid><wfw:comment>http://m.tkk7.com/boluobn/comments/135056.html</wfw:comment><comments>http://m.tkk7.com/boluobn/articles/135056.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://m.tkk7.com/boluobn/comments/commentRss/135056.html</wfw:commentRss><trackback:ping>http://m.tkk7.com/boluobn/services/trackbacks/135056.html</trackback:ping><description><![CDATA[<h2>教程QGridlg的简易分?/h2> <p><label>概述:</label> 本例会带你q入Grid分页的世?/p> <p>原文作者:Shea Frederick <a target=_blank>出处</a> </p> <p>参考图Q?br><a target=_blank></a></p> <p>读者应先下载本例涉及的<a target=_blank>C代码</a>。这里是一个已l完成好?a target=_blank>例子</a>?/p> <h2>Gird数据</h2> <p>Grid的分必M靠服务端QServer SideQ来划分好每一늚数据才可以完成?</p> <p>本例中的服务端语a是PHP,数据库是MySQLQ用来导Z些随机的数据。下列脚本的作用是,获取我们惌的数据,同时q些数据是已分好늚数据。分늚参数是由Page Toolbar传入的变量limit和start所军_的?</p> <pre><code> $link = mysql_pconnect("test-db.vinylfox.com", "test", "testuser") or die("Could not connect"); mysql_select_db("test") or die("Could not select database"); $sql_count = "SELECT id, name, title, hire_date, active FROM random_employee_data"; $sql = $sql_count . " LIMIT ".$_GET['start'].", ".$_GET['limit']; $rs_count = mysql_query($sql_count); $rows = mysql_num_rows($rs_count); $rs = mysql_query($sql); while($obj = mysql_fetch_object($rs)) { $arr[] = $obj; } Echo $_GET['callback'].'({"total":"'.$rows.'","results":'.json_encode($arr).'})'; </code> </pre> <p>׃每个后台开发的环境都不相同,所以这里的服务端代码就不细I了?/p> <h2>怎么做一个分늚Grid</h2> <p>本例采用的是<em>ScriptTagProxy</em>Q原因是 范例代码 ?服务端代?不是在同一个服务器上(译注Q即“跨域”Q,而大多数的情冉|Q在同一个服务器上得到数据,直接用HttpProxy可以了?/p> <p>使用DataStore与^时唯一不同的地方,便是需要设|?em>totalProerty</em>属性。本例中Q我们从服务端的脚本计算?#8220;total”q个|告诉DataStored有多个记录Q这里指的是所有的记录数?/p> <pre><code> var ds = new Ext.data.Store({ proxy: new Ext.data.ScriptTagProxy({ url: 'http://www.vinylfox.com/yui-ext/examples/grid-paging/grid-paging-data.php' }), reader: new Ext.data.JsonReader({ root: 'results', totalProperty: 'total', id: 'id' }, [ {name: 'employee_name', mapping: 'name'}, {name: 'job_title', mapping: 'title'}, {name: 'hire_date', mapping: 'hire_date', type: 'date', dateFormat: 'm-d-Y'}, {name: 'is_active', mapping: 'active'} ]) }); </code> </pre> <h2>分页栏Toolbar</h2> <p>q里加入一个分|到Grid的面板中Q?-差不多完成喽?/p> <pre><code> var gridFoot = grid.getView().getFooterPanel(true); var paging = new Ext.PagingToolbar(gridFoot, ds, { pageSize: 25, displayInfo: true, displayMsg: 'Displaying results {0} - {1} of {2}', emptyMsg: "No results to display" }); </code> </pre> <p>最后传?em>start</em>?em>limit</em>参数以初始化数据?/p> <pre><code> ds.load({params:{start:0, limit:25}}); </code> </pre> <p>花时间较多的地方是,在后台如何生成数据,以配合Grid的运作,一旦这些工作OK后,分页Grid再不是一仉事了?/p> <img src ="http://m.tkk7.com/boluobn/aggbug/135056.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://m.tkk7.com/boluobn/" target="_blank">菠萝</a> 2007-08-07 20:21 <a href="http://m.tkk7.com/boluobn/articles/135056.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>学习EXTW四?-开始用Gridhttp://m.tkk7.com/boluobn/articles/135057.html菠萝菠萝Tue, 07 Aug 2007 12:21:00 GMThttp://m.tkk7.com/boluobn/articles/135057.htmlhttp://m.tkk7.com/boluobn/comments/135057.htmlhttp://m.tkk7.com/boluobn/articles/135057.html#Feedback0http://m.tkk7.com/boluobn/comments/commentRss/135057.htmlhttp://m.tkk7.com/boluobn/services/trackbacks/135057.html 本教E将以XML为数据源Q带你进入Grid的世界?/p>

本文涉及的范例代码,可以在这里下载。一个完成好的例子可在这里找到?/p>

步骤一 定义数据(Data Definition)

首先要让Grid知道XML文定义了每一行是什么数据。正如所见,我们命名?item"在下面的XMLh中?/p>

单行的XMLh数据

<Item>
<ASIN>0446613657</ASIN>
<DetailPageURL>http://www.amazon[*SNIP*]JVQEG2</DetailPageURL>
<ItemAttributes>
<Author>Sidney Sheldon</Author>
<Manufacturer>Warner Books</Manufacturer>
<ProductGroup>Book</ProductGroup>
<Title>Are You Afraid of the Dark?</Title>
</ItemAttributes>
</Item>

接着需要定义某一列ؓ“l一标识QUnique IdentifierQ?#8221;,即ID,Ҏ(gu)“id"所讄的那个节Ҏ(gu)d|h代码W九(ji)行)。本例中的样本数据是”ASIN"列?/p>

数据定义的最后部分就是指定你需要显C的字段(Fields),把这些字D|C个数l之中,q保证这些字D与你的XML数据中元素名U是一致的Q而且q要注意先后序Q这里的序不需要和XML文g中顺序一致?/p>

    var dataStore = new Ext.data.Store({
proxy: new Ext.data.HttpProxy({url: 'sampledata-sheldon.xml'}),
reader: new Ext.data.XmlReader({
record: 'Item',
id: 'ASIN'
}, [
'Author', 'Title', 'Manufacturer', 'ProductGroup'
])
});

 

 

步骤?列模型(Column ModelQ?/h3>

下一步便是定义Column Model 列模型。简单地_是通过一些属性的讄Q决定每一列怎么控制或怎么昄Q这是一个由每列的配|参数组成的数组。注意,出现的顺序应该与刚才定义“字段”的数l一致。较常见的参数通常是header和widthQ所以你会觉得这两项是必要讄的,然而宽度(widthQ其实不L需要的Q因为稍后我们将使用autoWidth/Height来代ѝ?/p>

列模型样?/strong>

	var colModel = new Ext.grid.ColumnModel([
{header: "Author", width: 120, dataIndex: 'Author'},
{header: "Title", width: 180, dataIndex: 'Title'},
{header: "Manufacturer", width: 115, dataIndex: 'Manufacturer'},
{header: "Product Group", width: 100, dataIndex: 'ProductGroup'}
]);

最后是DataStore和Column Model两样东西传入到GridQ渲染结果,然后加蝲来自DataStore的数据,q些是你让Grid工作h的所有因素!

q行渲染Q?/strong>

    var grid = new Ext.grid.Grid('mygrid', {
ds: dataStore,
cm: colModel
});
grid.render();
dataStore.load();


菠萝 2007-08-07 20:21 发表评论
]]>
学习EXTW六?-关于?wi)TreePanel(Part 1)http://m.tkk7.com/boluobn/articles/135054.html菠萝菠萝Tue, 07 Aug 2007 12:19:00 GMThttp://m.tkk7.com/boluobn/articles/135054.htmlhttp://m.tkk7.com/boluobn/comments/135054.htmlhttp://m.tkk7.com/boluobn/articles/135054.html#Feedback0http://m.tkk7.com/boluobn/comments/commentRss/135054.htmlhttp://m.tkk7.com/boluobn/services/trackbacks/135054.htmlhttp://www.ajaxjs.com/yuicn/article.asp?id=20070245Q翻译文章)?span id=mark-0 title="66 comments" contentindex="0">http://www.jackslocum.com/blog/2006/12/29/preview-drag-and-drop-enhancements-and-the-new-treepanel/ Q原文)

一、加载一个同步Tree:

var TreeTest = function(){
var Tree = YAHOO.ext.tree;// 快捷方式

return {
init : function(){
var tree = new Tree.TreePanel('tree_div', {//需要一个tree_div的holder
animate:true, //是否动画
loader: new Tree.TreeLoader({dataUrl:'get_nodes.asp'}), //调用一个JSON
enableDD:false,// 是否支持拖放
containerScroll: true
});

// 讄根节?br> var root = new Tree.AsyncTreeNode({
text: 'Frank的作?, //根节Ҏ(gu)?br> draggable:false, //根节Ҏ(gu)否可拖放
id:'source'
});
tree.setRootNode(root); // 渲染 tree
tree.render(false,false);
// false for not recursive (the default), false to disable animation
root.expand(false,false);
}
};
}();

YAHOO.ext.EventManager.onDocumentReady(TreeTest.init, TreeTest, true);

通过XHR调用q个get_nodes.asp文gQ假设服务器q回q样一个JSON(有关JSON的介l?http://www.json.org/json-zh.html)Q?/p>

[{
"text":"yui-ext.js","id":"\/yui-ext.js","leaf":true,"cls":"file"
} ,{
"text":"yui-ext-1118.php","id":"\/yui-ext-1118.php","leaf":true,"cls":"file"
} ,{
"text":"yui-ext-1228.php","id":"\/yui-ext-1228.php","leaf":true,"cls":"file"
} ,{
"text":"build","id":"\/build","cls":"folder"
} ,{
"text":"source","id":"\/source","cls":"folder"
} ,{
"text":"yui-ext-1123.php","id":"\/yui-ext-1123.php","leaf":true,"cls":"file"
} ,{
"text":"yui-ext-1203.php","id":"\/yui-ext-1203.php","leaf":true,"cls":"file"
} ]
Server端JSON的输出(ASP JScriptQ?
var goods = new dbOpen();
goods.GetSQL ="select * from goodsbigclass";
with(goods){
GetRS(1);
var str="";
str+="[";
do{
str+='{"text":"'+rs("BigClassName")+'","id":"\/yui-ext.js","leaf":true,"cls":"file","href":"?b_id='+rs("BigClassID")+'"},';
rs.MoveNext();
}while(!rs.EOF);
str+="]";
Response.Write(str);
Close();
}
goods= null;

解释Q?br>“text”-->昄的文?br>"id"-->id?
“leaf”-->Boolean|如果“叶子”是真的话Q则不能包含子节点Children nodes
"cls"-->选用的样式,通常在这里选定图标
”href“-->指定的urlQ还有一?#8221;hrefTarget“的属?br>另外Q除了以上的属性,(zhn)还可以在JSON加入M的属性,作ؓ节点的属性,见Jack原话Q?br>The href attribute is called "href", there's also an "hrefTarget" attribute. For capturing node clicks, you can listen on individual nodes or you can listen for "click" on the tree which will pass you the node that was clicked. FYI, you can put any attributes you want in the json config for the node and it will be available as node.attributes. FAQ.4会l解释这个问题?br>FQA常见问题Q?/p>

1.Tree支持XML数据交换吗?
A:暂不支持Q据FOURM上的话,以后会提供支持,见:
can I use xml instead of json for sending nodes hirerachy Q?br>Correct me if I'm wrong but I think the answer is no here. But that doesn't mean it won't be supported later on.

2.我想用单M替双d开子节点,可以吗?
A:可以Q见Q?

tree.on('click', function(node){
if(!node.isLeaf()){
node.toggle();
}
});

 

3.事g处理的几U情形:
A: a.当加入某个节Ҏ(gu)Qؓ其增加事?

tree.on('append', function(tree, node){
if(node.id == 'foo'){
// q里加入你的事gQ如clickQ侦听器QaddListener()Q?
}
});

b.针对某个节点的单M?

tree.on('click', function(node){
if(node.id == 'foo'){
// do something
}
});

c.针对某个区域Q集合)的事?

// fires any time the selection in the tree changes
tree.getSelectionModel().on('selectionchange', function(sm, node){
if(node && node.id == 'foo'){
// do something
}
});

 

4.如何获取JSON中的自定义字D(或称作参?parametersQ?br>A:JSON对象已经被构建函?construction传递到TreeNode中,作ؓnode.attributes 出现Q所以调用属性node.attributes 便可获取。详见:http://www.yui-ext.com/forum/viewtopic.php?t=2253

tree.on('click', function(node){
if(!node.isLeaf()){
node.toggle();
}
});

 



菠萝 2007-08-07 20:19 发表评论
]]>
学习EXTW六?-关于?wi)TreePanel(Part 2异步获取节点)http://m.tkk7.com/boluobn/articles/134999.html菠萝菠萝Tue, 07 Aug 2007 08:44:00 GMThttp://m.tkk7.com/boluobn/articles/134999.htmlhttp://m.tkk7.com/boluobn/comments/134999.htmlhttp://m.tkk7.com/boluobn/articles/134999.html#Feedback0http://m.tkk7.com/boluobn/comments/commentRss/134999.htmlhttp://m.tkk7.com/boluobn/services/trackbacks/134999.html

下面介l如何异步取一|(wi)的所有节点,具体做法与官方同步取节点有很大不同,其在json的id属性上Q下面是我一些摸索,可能不是最x案,有待大家一L(fng)I?/p>

异步取节点的思\是这L(fng)Q?br>1、先定义一个初始化节点Q也可以不定义,看个人需求)
2、yui-extҎ(gu)该节点idh服务器,获得子节点各属?br>3、@?br>
特点Q可以在上一U目录中Q在服务器端预先该节点是否有子节点dQjson中的isLeaf属性)Q虽然但数据库将多承担一些压力,但用个count(*)不会造成太大负担Q除非查询条件异常复杂)Q也可以不读Q即把所有isLeaf讄为false?br>

问题Q?/strong>
1、目前还无法q行reloadQ即每次打开节点都重新读取一?br>2、样式还有些问题Q无法通过node. childNodes[i]讄子节点的styleQ所以无法改变最后一U元素的styleQ也许是通过别的途径改变style的?Q?/p>

 

CZQ?/strong>
先给ZDjs代码Q可以结合官方的demoQ?a target=_blank>http://yui-ext.com/playpen/yui-ext.0.40/examples/tree/reorder.htmlQ看看:

//定义根id的变?
var rootId = 1;
var TreeTest = function(){
// shorthand
var Tree = YAHOO.ext.tree;
return {
init : function(userName){
var tree = new Tree.TreePanel('detailTree', {
animate:true,
//q个dataUrl是初始化?wi)所用的urlQ你也可以不写或定义一个静态json文gQ还可以什么都不写全部依赖于第二个url自动产生Q视具体需求而定
loader: new Tree.TreeLoader({dataUrl:'calendarDetail.do?method=getDayDetailJSON&parentId='+rootId}),
enableDD:true,
containerScroll: true
});
// set the root node
var root = new Tree.AsyncTreeNode({
text: 'yui-ext',
draggable:false,
id:rootId
});
tree.setRootNode(root);
//Ҏ(gu)当前节点idQ动态拼求服务器的\?
//每生一个节点,指向一个事件的引用Q将新徏loader.dataUrlQ具体事件的机制q需要再研究Q?
//注意调用函数是beforeload
tree.on('beforeload', function(node){
tree.loader.dataUrl = 'calendarDetail.do?method=getDayDetailJSON&parentId='+node.id;
});
//q里演示一个自定义json的用?description定义json的key)
//以及如何定义某节点的style(node.ui.textNode.style.title)
//具体可以看uiq个c?
tree.on('beforeexpand', function(node){
node.ui.textNode.style.title = ‘red’;
alert(node.attributes.description);
});
// render the tree
tree.render();
// false for not recursive (the default), false to disable animation
root.expand();
}
};
}();

同时再分析一个jsonQ?br>[{"text":"衣服c?, 
"id":"5",     //注意Q这里是该节点的idQ拼q接时要用到Q与官方的json有所不同
"leaf":true,
"cls":"file",
"description":"q里是服类"}]   //自定义只需要这样就可以?

l出java产生json的代码逻辑片断Q?

 

……
//list为由传入的id所求的category集合
List list=
findBy("parentId", new Long(parentId.toString()));
StringBuffer JSONStr = new StringBuffer();  //声明json
JSONStr.append("[");
for(CostCategory i : list){
boolean isLeaf = isLeaf(i.getId());  //isLeaf()为判断是否有以该id为parentId的节点,具体没有l出
String icon = isLeaf?"file":"folder";
String description = i.getCategoryDescription()==null?"":i.getCategoryDescription();
//{"text":"treedata.jsp","id":"treedata.jsp","leaf":true,"cls":"file"},
JSONStr.append("{\"text\":\""+
i.getCategoryName()+"\",\"id\":\""+
i.getId()+"\",\"leaf\":"+
isLeaf+",\"cls\":\""+
icon+"\",\"description\":\""+
description+"\"},");
}
JSONStr.deleteCharAt(JSONStr.lastIndexOf(","));
JSONStr.append("]");
System.out.println(JSONStr);
out.print(JSONStr);   //输出json
……


菠萝 2007-08-07 16:44 发表评论
]]>
学习EXTW七?-关于View&JSONViewhttp://m.tkk7.com/boluobn/articles/134960.html菠萝菠萝Tue, 07 Aug 2007 06:29:00 GMThttp://m.tkk7.com/boluobn/articles/134960.htmlhttp://m.tkk7.com/boluobn/comments/134960.htmlhttp://m.tkk7.com/boluobn/articles/134960.html#Feedback0http://m.tkk7.com/boluobn/comments/commentRss/134960.htmlhttp://m.tkk7.com/boluobn/services/trackbacks/134960.html展现一条一条的二维关系的数据,我们可以使用GIRDlg?但有些场合,如品展C,dQ我们可以用ViewlgQ来展示“矩阵”式的数据?View的数据源来自DataModel对象Q即包含XMLDataModel和JSONDataModel。尽View支持JSON,但如果不是用于DataModelQView的子cJSONView更适用Q因为它提供更多的事件和Ҏ(gu)。一般来_View用于XML数据源;JSONView用于JSON数据源?/p>

View如何工作Q?/p>

记得以前如何输出一个记录吗Q以|上商店Z子;以前是这栯Z个商品的Q?

<%
  .....
  //下列服务端代码ؓASP using JScriptQ依然是JSQI'm a big JS Fan^^Q?br>  var str ="";
  str+="<td><div id='title'>";
  str+=rs("title")+"<\/div>";
  str+="<img src="+rs("thumb_image")+">";
  str+="<\/td>"
  Resposne.Write(str);
  .....
%>
很明显,我们最l目的还是要输出HTML,为浏览器渲染(Render)服务。View工作原理也一P只不q把以前Sever做的事情搬到Cilent来,依靠View来处理(实质上是Domhelper的模版)Q让览器最l渲染输出?/p>

需要你的帮忙:Domhelper

如上qͼView的工作离不开DomHelpr。DomHelpr在这里提?模版Template",q将其编译。见下面代码Q?

//新徏一个Template对象
var tpl = new YAHOO.ext.Template(    '<div class="entry">' +        '<a class="entry-title" href="{link}">{title}</a>' +       '<h4>{date} by {author} | {comments} Comments</h4>{description}' +    '</div><hr />');
tpl.compile(); //compile()的方法,可带来DOM性能的增?br>var moreView = new YAHOO.ext.JsonView('entry-list', tpl, {
   jsonRoot: 'posts'
});
//又或者隐式创建Template对象
var view = new YAHOO.ext.View('my-element',
           '<div id="{0}">{2} - {1}</div>', // auto create template
           dataModel, {
              singleSelect: true,
              selectedClass: 'ydataview-selected'
           });


 

加蝲数据

VIEW加蝲数据的方式与JSONView的有所不同QVIEW采用DataModel的load(),JSONView采用UpateManager的load()。下面重点说说JSONView的load()Ҏ(gu)Q?

 view.load({ url: 'your-url.php', params: {param1: 'foo', param2: 'bar'}, // 可以是URL encoded字符 callback: yourFunction, scope: yourObject, //(optional scope)  discardUrl: false,  nocache: false, text: 'Loading...',//loading之提C文?timeout: 30,//时 scripts: false });
只有url参数是不可缺省的Q其它如 nocache, text and scripts都是可选的?text和scripts是与UpdateManger实例兌的参?

params : String/Object
(optional) The parameters to pass as either a url encoded string "param1=1&param2=2" or an object {param1: 1, param2: 2}
callback : Function
(optional) Callback when transaction is complete - called with signature (oElement, bSuccess)
discardUrl : Boolean
(optional) By default when you execute an update the defaultUrl is changed to the last used url. If true, it will not store the url.
JSONView使用Ҏ(gu)

a.有一个gird和JSONView,两者如何同时调用一个数据源Q?br>1.改变jsonData属? 2.Call refresh(); ?a >http://www.yui-ext.com/forum/viewtopic.php?t=1968

b.分页
分页视乎q没有什么好的方案,JACK只提供下面的思\Q?br>JsonView extends View. View supports using a JSONDataModel. It won't render a paging toolbar for you, but it will loadPage() and standard DataModel functionality. The view will automatically update when you load new data. If you want named template parameters (like JsonView), you will need to remap the indexes (DataModel style) to named parameters. See the YAHOO.ext.View docs for more info on that.
http://www.yui-ext.com/forum/viewtopic.php?t=2340

c.如何JSONView的获取整个DataModel而不是字D?我每ơ用alert(mainView.jsonData); l果?#8220;undefined”
如果是获取DataModelQ那应该用View对象。出现undefined的原因是load()是异步的Q你必须先等待数据load完。如Q?/p>

mainView.el.getUpdateManager().on('update', function(){
     alert(mainView.jsonData);
});
详见http://www.yui-ext.com/forum/viewtopic.php?t=1209

 

d.学习例子。范例Image Chooser本n是一个好的学习例?/p>

JSON Format
(zhn)可能认为服务输L(fng)JSONQ?/p>

{"user": {"username": "Bob", "birthday": "1976-11-08", "join_date": "2006-08-01", "last_login": "2006-12-03"}}
是正无误的。但不对Q它是不能被处理的。正的格式应该是:

{"user": [{"username": "Bob", "birthday": "1976-11-08", "join_date": "2006-08-01", "last_login": "2006-12-03"}]}
注意Ҏ(gu)号内声明的是数组cdQView渲染方式实际是与DataModel一致的

 



菠萝 2007-08-07 14:29 发表评论
]]>
学习EXTW七日B-View&JSONView 一个画室网站的案例http://m.tkk7.com/boluobn/articles/134959.html菠萝菠萝Tue, 07 Aug 2007 06:27:00 GMThttp://m.tkk7.com/boluobn/articles/134959.htmlhttp://m.tkk7.com/boluobn/comments/134959.htmlhttp://m.tkk7.com/boluobn/articles/134959.html#Feedback0http://m.tkk7.com/boluobn/comments/commentRss/134959.htmlhttp://m.tkk7.com/boluobn/services/trackbacks/134959.html之前在Part 1单介l了Veiw和JSONView。今天这里小弟ؓ大家说说应用的案例,原本Jack的Image Chooser是一个非常好的案例,当中包含Jack大量的技巧,不过正因Pq于深奥Q小弟我亦不能一时全盘吃透,只挑?#8220;_֦”之处Q与君共勉之Q?br>本文包含四大知识点:1.在LayoutDialog中加入TabsQ?.View的用方式;3.JSONView的用方?4.获取XML/JSON的fieldsg分页

演示地址

【View之定义?br>  A View is generally used to build a quick template-based display of datamodel, rather than building a more complex grid. I thnk there's a blog post that illustrates doing this with JSON data. Templates can be used for any repetitious html creation, not necessarily tied to a datamodel.
主要的意思是View用于展示DataModel的数据,Part 1已经说过。这里是来自fourm某君的补充?/p>

代码点评Q?/p>

1.先看一D늮单的

 

Title//用yui.ext做翻转按? super easy(工最??^^)
showBtn = getEl('showIntro');
showBtn.on('click', this.showDialog, this, true);
showBtn.applyStyles("cursor:pointer");
showBtn.on('mouseover', function(){showBtn.dom.src='images/over_10.gif'}, this, true);
showBtn.on('mouseout', function(){showBtn.dom.src='images/btn_10.gif'}, this, true);

 


Title//左边动画效果,createDelegate()负责轮换效果
var luo=getEl("left_pic");
luo.move('right', 250, true, .1, function(){
   luo.dom.src='images/'+who+".gif";
   luo.move('left', 250, true, .15, null, YAHOO.util.Easing.easeOutStrong);
}.createDelegate(this));

 

2.在LayoutDialog中加入Tabs

LayoutDialong分两个区域:west & center。而center之中我们要加入tabsQƈ逐一附加active的事?/p>

   

Title

var center = layout.getRegion('center');
var tab1 = new YAHOO.ext.ContentPanel('luo', {title: '|老师作品'});
center.add(tab1);
center.add(new YAHOO.ext.ContentPanel('chen', {title: '陈老师作品'}));

//center.on('panelactivated',function(){
//  alert(center.titleTextEl);
//}, this, true);
//center.showPanel('center');      
/*two ways to activate the tabs.and tabs= many CPs
如果在BasicDialog中,只需要dialog本n可以获取getTabs,因ؓDialog本n是
唯一的一个Region;
但在LayoutDialog中,Region是多个的Q所有要指明哪个一个Region才行
*/

 // stoe a refeence to the tabs 获取TABS集合
var tabs = layout.getRegion('center').getTabs();//逐一加入事g
tabs.getTab('center').on('activate', function(){this.show_thumb('student')}, this, true);
tabs.getTab('luo').on('activate', function(){this.show_thumb('luo')}, this, true);
tabs.getTab('chen').on('activate',function(){this.show_thumb('chen')}, this, true); 
//center.showPanel('chen'); //用RegionȀzM可以
/*Tips:不能立即ȀzMӞ会点延时Q经q多行代码的延时便ok Q用addbufferlistener理论上也可以*/
layout.getRegion('center').getTabs().activate('center'); 3.View的用方?

//XML:index方式讉K字段QJSONQ直接用字D名
var tpl = new YAHOO.ext.Template(
 '<div class="thumb">'+
 '<div><img onclick=popupDialog("userfiles/image/'+who+'/{0}",{2},{3}) '+
 ' src=userfiles/image/lite_'+who+'/{0}></div>' +
 '<div>文g大小: {1}</div>'+
 '</div>'
);
tpl.compile(); //“~译DOM”加?/p>

var schema = {
 tagName: 'row',//Item?br> id: 'id',//ID如不需要时Q设|空白字W串Q不能取消!
 Fields: ['filename','filesize','width','height']//d的字D?br>};
var dm = new YAHOO.ext.grid.XMLDataModel(schema);
var mainView = new YAHOO.ext.View('pic_'+who,
tpl,
dm, {
 singleSelect: true,//If JSON,q需指定一个config:jsonRoot
 emptyText : '<div style="padding:10px;">没有匚w的内容!</div>'
});
dm.on('load',function(){}, this, true);
mainView.on('click', function(vw, index, node, e){
 //alert('Node "' + node[] + '" at index: ' + index + ' was clicked.')
},this, true);
mainView.prepareData = function(data){
 // prepare,用于自定义格?br> //如JSON方式直接属性名讉KQe.g data.sizeString = formatSize(data.size);
 data[1] = formatSize(data[1]);
 return data;
};
//用DataModel加蝲文gQ如果是JSONViewQ这个服务由JSONView本nQUpdateManagerQ提?br>dm.load('xml.asp?who='+who); 


4.JSONView的用方?

 

Title

var dh = YAHOO.ext.DomHelper;
dh.append(document.body, {tag: 'div', id: 'editUserDialog-user'});
//XML:index方式讉K字段QJSONQ直接用字D名
var tpl = new YAHOO.ext.Template('Username: {username}' +
'Birthday: {birthday}' +
'Member Since: {join_date}' +
'Last Login: {last_login}');
tpl.compile();
var mainView = new YAHOO.ext.JsonView('pic',
tpl, {
   singleSelect: true,
   jsonRoot: 'user',
   emptyText : 'No images match the specified filter'
});
mainView.load("test.asp", "id=2");
//JSONViewҎ(gu)的异怺?br>mainView.on('loadexception', function(){onLoadException()}, this, true);

var onLoadException= function(v,o){
   alert('Error');
};


5.获取XML/JSON的fieldsg分页

 

q两个问题放在一赯论的原因是至今我q不能实现。如果按照jack的办法:

TitlemainView.on('click', function(vw, index, node, e){
 alert('Node "' + node.id + '" at index: ' + index + ' was clicked.');
});

可得到index但node.id无法获取。我只好用较丑陋的方式实玎ͼ
Title//在Domhelper?#8220;?#8221;输出click事g
var tpl = new YAHOO.ext.Template(  '<div class="thumb">'+ '<div><img onclick=popupDialog("userfiles/image/'+who+'/{0}",{2},{3}) '+ ' src=userfiles/image/lite_'+who+'/{0}></div>' +  '<div>文g大小: {1}</div>'+ '</div>');

分页Q?br>View的分视乎应该通过DataModel。但我没成功q。如知道~由的朋友恳请告之?br>

 



菠萝 2007-08-07 14:27 发表评论
]]>
学习EXTW八?EXT的布局QLayoutQ?/title><link>http://m.tkk7.com/boluobn/articles/134953.html</link><dc:creator>菠萝</dc:creator><author>菠萝</author><pubDate>Tue, 07 Aug 2007 06:16:00 GMT</pubDate><guid>http://m.tkk7.com/boluobn/articles/134953.html</guid><wfw:comment>http://m.tkk7.com/boluobn/comments/134953.html</wfw:comment><comments>http://m.tkk7.com/boluobn/articles/134953.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://m.tkk7.com/boluobn/comments/commentRss/134953.html</wfw:commentRss><trackback:ping>http://m.tkk7.com/boluobn/services/trackbacks/134953.html</trackback:ping><description><![CDATA[<p>Summary: 本文是区域管理器Qregion managerQ的教程的第一,为?zhn)介绍如何创徏区域Q如何增加版面到q些区域?</p> <p><br>Author:Dave Fenwick<br>Published: May 01, 2007<br>Translater: Frank Cheung </p> <p>Ext的layout布局对于建立WEBE序ؓ有用。关于布局引擎Qlayout engineQ,区域理器(region managerQ的教程分为几部分Q本文是W一,为?zhn)介绍如何创徏区域Q如何增加版面到q些区域?/p> <p>布局引擎(layout engine)q一功能早已在EXT前个ALPHA实现了?Jack Slocum对于怎样环绕某一区域Q给与指定区域管理的{略Q和建立界面的问题,在他的第一、第二篇关于跨浏览器的WEB2.0布局功能的博客中Q进行过讨论。定义一个DOM元素的边界(edgeQ,使之一个布局的边框(borderQ-Q这U做法得创?#8220;加厚?thickQlike)”客户端UI的开发更q一大步?/p> <p>布局理?layout manager)负责理q些区域。布局理的主要的用户lg是BorderLayoutcR该cMؓEXT开发富界面的程序提供了一个切入点。Layout的含意是划分好一些预定的区域。可用的区域分别有south, east, west, north,和center。每一个BorderLayout对象都提供这些区域但只有center要求必须使用的。如果你在单独一个区域中包含多个面板Q你可通过NestedLayoutPanel cd嵌到BorderLayout 实例中?/p> <p>注意事项Q本教程的每个文仉?html?js格式的。教E每一步都有演C?你也可以下蝲q些文g在编辑器Qzip格式提供在这里)中看看发生什么事?/p> <p>面板QPaneQ是区域理Qregion managementQ的另外一个组件。面板提供了q么一个地方,可ؓ(zhn)的EXT器gQwidgetQ、加载的HTML,嵌入的IFrames、或者是你日常在HTML面上摆攄随便一样东ѝNestedLayoutPanel也是一个面板,只不q用于链接多个BorderLayout的区域,其它的面板包括内定w?ContentPanel,GRID面板 GridPanel,和树(wi)犉?TreePanel?/p> <p>单的例子<br>下面的layout包含 north, south, east, west,和center的区域,而且每个区域包含一个ContentPanelQ各区域之间使用得了分隔条分割开?/p> <p> </p> <p> <fieldset><legend>Title</legend>var mainLayout = new Ext.BorderLayout(document.body, <br>{<br>    north: { <br>        split: true, initialSize: 50 <br>    },<br>    south: {<br>        split: true, initialSize: 50 <br>    },<br>    east: { <br>        split: true, initialSize: 100 <br>    }, <br>    west: { <br>        split: true, initialSize: 100 <br>    }, <br>    center: {<br>    }<br>});</fieldset><br>q是一个非常基本的layout,只是分配了东南西北中间的区域、分隔条、设|一下初始尺寸,q最q定义中间区域。本例中QBorderLayout被绑定到"document.body"q个DOM元素Q其实BorderLayoutq可以绑定到M一个封闭的DOM元素。定义好BorderLayout之后Q我们加入ContentPanel对象Q基于本例)? <p> </p> <p> <fieldset><legend>Title</legend>mainLayout.beginUpdate();<br>mainLayout.add('north', new Ext.ContentPanel('north-div', {<br>    fitToFrame: true, closable: false<br>}));<br>mainLayout.add('south', new Ext.ContentPanel('south-div', {<br>    fitToFrame: true, closable: false <br>}));<br>mainLayout.add('east', new Ext.ContentPanel('east-div', {<br>    fitToFrame: true, closable: false<br>}));<br>mainLayout.add('west', new Ext.ContentPanel('west-div', {<br>    fitToFrame: true, closable: false<br>}));<br>mainLayout.add('center', new Ext.ContentPanel('center-div', {<br>    fitToFrame: true<br>}));<br>mainLayout.endUpdate();</fieldset><br>当前的例子是ContentPanel加入到所有区域中。由调用mainLayout.beginUpdate()开始。beginUpdate()告诉BorderLayout对象在执行endUpate()Ҏ(gu)之前Q先不要对加入的对象排版布局。这L(fng)好处是避免了ContentPanel有对象加入时Q导致UI的刷斎ͼ改进了整体的用户体验。执行beginUpdate()之后Q加入五个ContentPanel对象到区域。所有的ContentPanel对象Q除中间的那个外Q,都设|是可关闭的QclosbaleQ。所有的ContentPanel对象也都讄动适配它们的父元素。最后执行endUpdate()渲染layout? <p> </p> <p> </p> <p>InternetExploer注意事项QBorderLayout所容纳的元素必L一个SIZE以便正确渲染。典型地你无Mؓdocument.body 指明sizeQ因为document.body通常是有size的了Q大多数情况Q-如果你在览器上什么也看不刎ͼ。但是如果你layoutq同容器攑ֈ现有的web面上(‘可能是DIVQ?那么DIV的size应该先指明以便正渲染。如下列昄正常Q?/p> <p>好,让我们趁热打铁,看看完整的layout是怎样的。假设ext是一子目录叫做ext-1.0Q父目录下面的代码?/p> <p>simple.html:</p> <p> <fieldset><legend>Title</legend><body><br>    <div id="north-div"></div><br>    <div id="south-div"></div><br>    <div id="east-div"></div><br>    <div id="west-div"></div><br>    <div id="center-div"></div><br></body></fieldset> <p> </p> <p><br>simple.js:</p> <p> <fieldset><legend>Title</legend>Simple = function() {<br>    return {<br>        init : function() {<br>            var mainLayout = new Ext.BorderLayout(document.body, {<br>                north: {<br>                    split: true, initialSize: 50<br>                },<br>                south: {<br>                    split: true, initialSize: 50<br>                },<br>                east: {<br>                    split: true, initialSize: 100<br>                },<br>                west: {<br>                    split: true, initialSize: 100<br>                },<br>                center: {<br>                }<br>            });<br>            mainLayout.beginUpdate();<br>            mainLayout.add('north', new Ext.ContentPanel('north-div', {<br>                fitToFrame: true, closable: false <br>            }));<br>            mainLayout.add('south', new Ext.ContentPanel('south-div', {<br>                fitToFrame: true, closable: false<br>            }));<br>            mainLayout.add('east', new Ext.ContentPanel('east-div', {<br>                fitToFrame: true, closable: false<br>            }));<br>            mainLayout.add('west', new Ext.ContentPanel('west-div', {<br>                fitToFrame: true, closable: false<br>            }));<br>            mainLayout.add('center', new Ext.ContentPanel('center-div', {<br>                fitToFrame: true<br>            }));<br>            mainLayout.endUpdate();<br>        }<br>    };<br>}();<br>Ext.EventManager.onDocumentReady(Simple.init, Simple, true);</fieldset><br>加入内容<br>上面的例子做的layout,除了可移动分割栏外,功能q不强大。需要加入些内容。有几种的办法加入内宏V如果?zhn)直接加入内容到DIV中(ContentPanell定的那个)QContentPanel对象会对div里面的内容进行渲染。尽试试!我们会更改html内容加入 center-div中? <p> </p> <p>simple2.html<br> <fieldset><legend>Title</legend><body><br>    <div id="north-div"></div><br>    <div id="south-div"></div><br>    <div id="east-div"></div><br>    <div id="west-div"></div><br>    <div id="center-div">This is some content that will display in a panel when a ContentPanel object is attached to the div.</div><br></body></fieldset><br>  <p> </p> <p>除此之外Q还可以利用ContentPanel对象带有的function加蝲数据。可用的Ҏ(gu)有几U,q里我们使用其中两种QsetContent() ?setUrl()。setContent()允许(zhn)直接从JavaSciptE序中插入HTML。setUrl()Q允许?zhn)从服务端得到数据加入ContentPanel中?/p> <p>我们原来的例子中QContentPanel对象创徏的时候是匿名的(anonymousQ。这没问题,但要引用它们Q你需要遍历区域管理器所分配的对象以获得引用的对象。这不是最好的办法Q所有我的做法是分配一个变量给ContentPanel然后便可直接引用?/p> <p>simple3.js</p> <p> <fieldset><legend>Title</legend>Simple = function() {<br>    var northPanel, southPanel, eastPanel, westPanel, centerPanel;<br>    return {<br>        init : function() {<br>            var mainLayout = new Ext.BorderLayout(document.body, {<br>                north: { <br>                    split: true, initialSize: 50 <br>                }, <br>                south: { <br>                    split: true, initialSize: 50 <br>                }, <br>                east: { <br>                    split: true, initialSize: 100 <br>                }, <br>                west: { <br>                    split: true, initialSize: 100 <br>                }, <br>                center: { <br>                }<br>            });<br>            mainLayout.beginUpdate();<br>            mainLayout.add('north', northPanel = new Ext.ContentPanel('north-div', { <br>                fitToFrame: true, closable: false <br>            }));<br>            mainLayout.add('south', southPanel = new Ext.ContentPanel('south-div', { <br>                fitToFrame: true, closable: false <br>            }));<br>            mainLayout.add('east', eastPanel = new Ext.ContentPanel('east-div', { <br>                fitToFrame: true, closable: false <br>            }));<br>            mainLayout.add('west', westPanel = new Ext.ContentPanel('west-div', { <br>                fitToFrame: true, closable: false <br>            }));<br>            mainLayout.add('center', centerPanel = new Ext.ContentPanel('center-div', { <br>                fitToFrame: true <br>            }));<br>            mainLayout.endUpdate();<br>            northPanel.setContent('This panel will be used for a header');<br>            westPanel.setContent('');<br>            centerPanel.setUrl('index.html');<br>            centerPanel.refresh();<br>        }<br>    };<br>}();<br>Ext.EventManager.onDocumentReady(Simple.init, Simple, true);</fieldset><br>我们现在从现有的面动态加载内宏V但是这里有个问题。若果内定w面积q大而撑破页面的话将没有意义了。我们提供了一些配|属性以解决q类问题。当fitToFrame为trueӞp动配|a(chn)utoScroll。内容一旦溢出就会出现滚动条。另外一个涉及InternetExploer的问?是中间的内容的样式没有生效,原因是一些浏览器支持动态样式而一些不直接Q要较好地解决上q问题,推荐使用Iframe标签? <p> </p> <p>用IFRAME标签做布局可灵zd处理Q我们准备在DOM中直接操UIFRAME.q里IFRAME成ؓ面板的容器,以填入中间区域的内容</p> <p>讄一?IFRAME的滚动条q放C间的面?</p> <p>simple4.html<br> <fieldset><legend>Title</legend><body><br>    <div id="north-div"></div><br>    <div id="south-div"></div><br>    <div id="east-div"></div><br>    <div id="west-div"></div><br>    <div id="center-div"><iframe id="center-iframe" frameborder="0" style="border:0px none;overflow:none"></iframe></div><br></body></fieldset> <p> </p> <p>simple4.js</p> <p> <fieldset><legend>Title</legend>Simple = function() {<br>    var northPanel, southPanel, eastPanel, westPanel, centerPanel;<br>    return {<br>        init : function() {<br>            var mainLayout = new Ext.BorderLayout(document.body, {<br>                north: { <br>                    split: true, initialSize: 50 <br>                }, <br>                south: { <br>                    split: true, initialSize: 50 <br>                }, <br>                east: { <br>                    split: true, initialSize: 100 <br>                }, <br>                west: { <br>                    split: true, initialSize: 100 <br>                }, <br>                center: { <br>                }<br>            });<br>            mainLayout.beginUpdate();<br>            mainLayout.add('north', northPanel = new Ext.ContentPanel('north-div', { <br>                fitToFrame: true, closable: false <br>            }));<br>            mainLayout.add('south', southPanel = new Ext.ContentPanel('south-div', { <br>                fitToFrame: true, closable: false <br>            }));<br>            mainLayout.add('east', eastPanel = new Ext.ContentPanel('east-div', { <br>                fitToFrame: true, closable: false <br>            }));<br>            mainLayout.add('west', westPanel = new Ext.ContentPanel('west-div', { <br>                fitToFrame: true, closable: false <br>            }));<br>            mainLayout.add('center', centerPanel = new Ext.ContentPanel('center-div', { <br>                fitToFrame: true, autoScroll: true, resizeEl: 'center-iframe'<br>            }));<br>            mainLayout.endUpdate();<br>            northPanel.setContent('This panel will be used for a header');<br>            Ext.get('center-iframe').dom.src = 'index.html';<br>        }<br>    };<br>}();<br>Ext.EventManager.onDocumentReady(Simple.init, Simple, true);</fieldset><br>  <p> </p> <p>当前的进展不错。大多数情况滚动条工作v来是很好的,但留意一L(fng)东西Q?Internet Explorer 7之前的版本,如果文完整指明DTD的DOCTYPE标签QIE很可能出现垂直滚动条的同时也昄水^滚动条。这个IE布局的一个BUG?/p> <p>现在q是个基本的LAYOUT和几个ContentPanel对象。接着我们加入一条工hQtoolbarQ到中间的ContentPanel对象。创E非常简单。由于主题的关系Q我q不准备在这里详l介l如何创建toolbat。这是简单的创徏toolbar的过E:</p> <p>var simpleToolbar = new Ext.Toolbar('simple-tb');<br>simpleToolbar.addButton({ text: 'Scroll Bottom', cls: 'x-btn-text-icon scroll-bottom'});<br>simpleToolbar.addButton({ text: 'Scroll Top', cls: 'x-btn-text-icon scroll-bottom'});要加入toolbar,需要先加入HTML的容器,我们需要加入一些代码以创徏toolbarQ然后绑定到中间的区域。toolbar有两个按钮: Scroll Bottom和Scroll Top。这些按钮会滚动IFRAME内容到底部或是顶部。ؓ了尽可能兼容多浏览器Q我们的加入一个function来控制IFRAME文?/p> <p>simple5.html<br> <fieldset><legend>Title</legend><html><br><body><br>    <div id="north-div"></div><br>    <div id="south-div"></div><br>    <div id="east-div"></div><br>    <div id="west-div"></div><br>    <div id="center-div"><br>        <div id="center-tb"></div><br>        <iframe id="center-iframe" frameborder="0" scrolling="auto" style="border:0px none;"></iframe><br>    </div><br></body><br></html></fieldset> <p> </p> <p>simple5.js</p> <p> <fieldset><legend>Title</legend> <p>function getIframeDocument(el) {<br>    var oIframe = Ext.get('center-iframe').dom;<br>    var oDoc = oIframe.contentWindow || oIframe.contentDocument;<br>    if(oDoc.document) {<br>        oDoc = oDoc.document;<br>    }<br>    return oDoc;<br>}</p> <p>Simple = function() {<br>    var northPanel, southPanel, eastPanel, westPanel, centerPanel;<br>    return {<br>        init : function() {<br>           var simpleToolbar = new Ext.Toolbar('center-tb');<br>           simpleToolbar.addButton({<br>               text: 'Scroll Bottom', cls: 'x-btn-text-icon scroll-bottom', handler: function(o, e) {<br>                   var iframeDoc = getIframeDocument('center-iframe');<br>                   iframeDoc.body.scrollTop = iframeDoc.body.scrollHeight;<br>               }<br>           });<br>           simpleToolbar.addButton({<br>               text: 'Scroll Top', cls: 'x-btn-text-icon scroll-top', handler: function(o, e) {<br>                   var iframeDoc = getIframeDocument('center-iframe');<br>                   iframeDoc.body.scrollTop = 0;<br>               }<br>           });<br>           var mainLayout = new Ext.BorderLayout(document.body, {<br>                north: { <br>                    split: true, initialSize: 50 <br>                }, <br>                south: { <br>                    split: true, initialSize: 50 <br>                }, <br>                east: { <br>                    split: true, initialSize: 100 <br>                }, <br>                west: { <br>                    split: true, initialSize: 100 <br>                }, <br>                center: { }<br>            });<br>            mainLayout.beginUpdate();<br>            mainLayout.add('north', northPanel = new Ext.ContentPanel('north-div', { <br>                fitToFrame: true, closable: false <br>            }));<br>            mainLayout.add('south', southPanel = new Ext.ContentPanel('south-div', { <br>                fitToFrame: true, closable: false <br>            }));<br>            mainLayout.add('east', eastPanel = new Ext.ContentPanel('east-div', { <br>                fitToFrame: true, closable: false <br>            }));<br>            mainLayout.add('west', westPanel = new Ext.ContentPanel('west-div', { <br>                fitToFrame: true, closable: false <br>            }));<br>            mainLayout.add('center', centerPanel = new Ext.ContentPanel('center-div', { <br>                fitToFrame: true, autoScroll: true, resizeEl: 'center-iframe', toolbar: simpleToolbar<br>            })); <br>            mainLayout.endUpdate();<br>            northPanel.setContent('This panel will be used for a header');<br>            Ext.get('center-iframe').dom.src = 'index.html';<br>        }<br>    };<br>}();<br>Ext.EventManager.onDocumentReady(Simple.init, Simple, true);</p> </fieldset><br>一个标准的layout已经差不多了。区域可讄标题Q这样可以把几个区域区分开来,创徏该区域面板的时候指定属性即可? <p> </p> <p>所有的区域都可以收~和展开。要使一个区域可收羃Q你应在区域配置中指定collapsible属性。属性collapsedTitle是用于区域收~之后显C的文字QcollapsedTitle属性只用于north和south区域?/p> <fieldset><legend>simple6.js</legend> <p>function getIframeDocument(el) {<br>    var oIframe = Ext.get('center-iframe').dom;<br>    var oDoc = oIframe.contentWindow || oIframe.contentDocument;<br>    if(oDoc.document) {<br>        oDoc = oDoc.document;<br>    }<br>    return oDoc;<br>}</p> <p>Simple = function() {<br>    var northPanel, southPanel, eastPanel, westPanel, centerPanel;<br>    return {<br>        init : function() {<br>           var simpleToolbar = new Ext.Toolbar('center-tb');<br>           simpleToolbar.addButton({<br>               text: 'Scroll Bottom', cls: 'x-btn-text-icon scroll-bottom', handler: function(o, e) {<br>                   var iframeDoc = getIframeDocument('center-iframe');<br>                   iframeDoc.body.scrollTop = iframeDoc.body.scrollHeight;<br>               }<br>           });<br>           simpleToolbar.addButton({<br>               text: 'Scroll Top', cls: 'x-btn-text-icon scroll-top', handler: function(o, e) {<br>                   var iframeDoc = getIframeDocument('center-iframe');<br>                   iframeDoc.body.scrollTop = 0;<br>               }<br>           });<br>           var mainLayout = new Ext.BorderLayout(document.body, {<br>                north: { <br>                    split: true, initialSize: 50 <br>                }, <br>                south: { <br>                    split: true, initialSize: 125, titlebar: true, <br>                    collapsedTitle: 'Status', collapsible: true<br>                }, <br>                east: { <br>                    split: true, initialSize: 100 <br>                }, <br>                west: { <br>                    split: true, initialSize: 100, titlebar: true, collapsible: true<br>                }, <br>                center: { titlebar: true}<br>            });<br>            mainLayout.beginUpdate();<br>            mainLayout.add('north', northPanel = new Ext.ContentPanel('north-div', { <br>                fitToFrame: true, closable: false <br>            }));<br>            mainLayout.add('south', southPanel = new Ext.ContentPanel('south-div', { <br>                fitToFrame: true, closable: false, title: 'Status'<br>            }));<br>            mainLayout.add('east', eastPanel = new Ext.ContentPanel('east-div', { <br>                fitToFrame: true, closable: false <br>            }));<br>            mainLayout.add('west', westPanel = new Ext.ContentPanel('west-div', { <br>                fitToFrame: true, closable: false, title: 'Navigation'<br>            }));<br>            mainLayout.add('center', centerPanel = new Ext.ContentPanel('center-div', { <br>                fitToFrame: true, autoScroll: true, resizeEl: 'center-iframe', <br>                toolbar: simpleToolbar, title: 'Content'<br>            })); <br>            mainLayout.endUpdate();<br>            northPanel.setContent('This panel will be used for a header');<br>            Ext.get('center-iframe').dom.src = 'index.html';<br>        }<br>    };<br>}();<br>Ext.EventManager.onDocumentReady(Simple.init, Simple, true);</p> </fieldset> <p> </p> <p>注意我们收藏起west区域Ӟ是没有title的。当前的HTML没有提供对一个元素的90度的旋{。我们只好用一张透明的图片来实现Q上面的文字?Navigation',?8p,?50p,然后90度旋转?/p> <p>Z昄囄Q我们需要增大EXT原先的widget样式Q只dHTML头样式表中加入下列样式便可得到适合的样式效果。如simple7.htmlC?/p> <p> <fieldset>.x-layout-collapsed-west {<br>    background-image: url(navigation.gif);<br>    background-repeat: no-repeat;<br>    background-position: center;<br>}</fieldset><br>教程的第二部分我们将会接触layout manager的一些高U细节内容,包括内嵌layoutsQ可~程的展开、收~区域,创徏tab layout和其它一些创建EXTellentE序的有效方法?br> <p> </p> <img src ="http://m.tkk7.com/boluobn/aggbug/134953.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://m.tkk7.com/boluobn/" target="_blank">菠萝</a> 2007-08-07 14:16 <a href="http://m.tkk7.com/boluobn/articles/134953.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>学习EXTW九(ji)日:表单入门http://m.tkk7.com/boluobn/articles/134949.html菠萝菠萝Tue, 07 Aug 2007 06:05:00 GMThttp://m.tkk7.com/boluobn/articles/134949.htmlhttp://m.tkk7.com/boluobn/comments/134949.htmlhttp://m.tkk7.com/boluobn/articles/134949.html#Feedback0http://m.tkk7.com/boluobn/comments/commentRss/134949.htmlhttp://m.tkk7.com/boluobn/services/trackbacks/134949.html摘要Q?本教E教你如何入手去创徏一个基本的表单?
Author: Shea Frederick
Translater:Hegz
Published: May 05, 2007
Translated:May 14,2007
出处Q?a >http://www.fleaphp.org.cn/bbs/viewthread.php?tid=906&page=1&extra=page%3D1#pid4736

我徏议下载用于这个例子的一D늨序,q样可能对你有一些帮助。你也可以找一个有效的例子?/p>

表单?br>首先要做的第一件事是创徏一个表单体Q这相当于在HTML中书写一?
标识?


var form_employee = new Ext.form.Form({
 labelAlign: 'right',
 labelWidth: 175,
 buttonAlign: 'right'
});
 创徏表单字段
表单CZ由name、title、hire_date和active四个表单字段构成。开头的两个表单字段name和titleQ只是简单的文本字段Q我们会用TextFieldҎ(gu)来创建它们?/p>

重要的配|选项是nameQ定义该选项与HTML中定义一个表单字D名几乎一栗?/p>


var employee_name = new Ext.form.TextField({
 fieldLabel: 'Name',
 name: 'name',
 width:190
});

var employee_title = new Ext.form.TextField({
 fieldLabel: 'Title',
 name: 'title',
 width:190
});
 跟着的hire_date字段是一个日期字D,我们会用DateFieldҎ(gu)来创建,它会为我们弹Z个别致的日期选择器来让我们选择日期?/p>

format配置选项被用来ؓPHP指定日期格式标准QPHP的日期格式)。日期格式字W串的调整须与你所用的日期格式相匹配?/p>

 

var employee_hire_date = new Ext.form.DateField({
 fieldLabel: 'Hire Date',
 name: 'hire_date',
 width:90,
 allowBlank:false,
 format:'m-d-Y'
});
 最后一个表单元素active是一个布?yu)(dng)|我们使用CheckboxҎ(gu)来创建?/p>


var employee_active = new Ext.form.Checkbox({
 fieldLabel: 'Active',
 name: 'active'
});
 完成表单
现在Q我们把表单里的所有表单字D加入到fieldset中去。当然了Q如果你惛_fieldset的外面进行,可以选择使用addҎ(gu)?


form_employee.fieldset(
 {legend:'Employee Edit'},
 employee_name,
 employee_title,
 employee_hire_date,
 employee_active
)
 最后,最不能的是submit按钮Q它与一段的错误检代码块一赯addButtonҎ(gu)加进来。当该按钮被点击Q就会调用renderҎ(gu)Q传入div标识?#8220;id”Q然后在|页的div里把表单昄出来?/p>


form_employee.addButton('Save', function(){
 if (form_employee.isValid()) {
  Ext.MessageBox.alert('Success', 'You have filled out the form correctly.'); 
 }else{
  Ext.MessageBox.alert('Errors', 'Please fix the errors noted.');
 }
}, form_employee);

form_employee.render('employee-form');
 下一?/p>

虽然本教E让你懂得了如何dZ个表单,但创建出来的表单什么事情也q不了。就像一部没有引擎的汽车——它看v来可能很漂亮Q但不能让你走得更远?br>



菠萝 2007-08-07 14:05 发表评论
]]>
学习EXTW九(ji)日(B):Z个表单填充或提交数据http://m.tkk7.com/boluobn/articles/134948.html菠萝菠萝Tue, 07 Aug 2007 06:04:00 GMThttp://m.tkk7.com/boluobn/articles/134948.htmlhttp://m.tkk7.com/boluobn/comments/134948.htmlhttp://m.tkk7.com/boluobn/articles/134948.html#Feedback0http://m.tkk7.com/boluobn/comments/commentRss/134948.htmlhttp://m.tkk7.com/boluobn/services/trackbacks/134948.html摘要Q这个教E将指导你如何获取数据到你的表单q将q些数据提交?
Author: Shea Frederick
Translater: pplboy
Published: May 22, 2007
Translater Date:May 30.2007

q个教程使用了在getting started tutorial教程中用过?雇员信息~辑表单。如果你仍然不熟(zhn)如何创Z个表单,你可以首先看一下这个例子。我下蝲用于q个例子的一D늨序,q样可能对你有一些帮助。你也可以找一个有效的例子?/p>

我们经历用表单的整个q程Q从最初的从服务器获取数据填入表单Q到数据返回给服务器。在后端我用PHP和MySQL, 然而这个例子对于PHP和MySQL来说q不是特D的Q而是只要求你能够从你的服务器d和输出JSON数据?/p>

让我们开始吧
首先我们必须讄表单的url, q是一个能获得POST数据q将其写q我们的数据库的PHP脚本.


var form_employee = new Ext.form.Form({
 ...
 url:'forms-submit-process.php',
 ...
});
 我们的数据包?个字D:id, name, title, hire_date和active,q些字段可以被取回ƈ攄C个数据存储对象(StoreQ中?/p>

以下的程序构造了一个数据存储对象,在这个时候没有数据被取回Q我们的数据代理QProxyQ对象提交到一个PHP脚本Q用来取回数据库id?4的行 q将它{换成一个JSON字符丌Ӏ?/p>


employee_data = new Ext.data.Store({
proxy: new Ext.data.HttpProxy({url: 'forms-submit-getdata.php?id=14'}),
reader: new Ext.data.JsonReader({},[ 'id', 'name', 'title', 'hire_date', 'active']),
remoteSort: false
});


接下来要做的是设定我们的事g监听者来监察什么时候数据被载入Q?q个保证我们不会在数据被蝲入之前填入表单?/p>


employee_data.on('load', function() {
 
 // data loaded, do something with it here...
   
});
 当数据被载入后,我们可以取回数据q用setValueҎ(gu)其填入表单。这里我们用getAt(0) 从我们的数据存储对象里重新取回第一行数据(行zeroQ?/p>


注意Q这里用的表单和表单字D在getting started tutorial中有定义和解释?/p>


employee_name.setValue(employee_data.getAt(0).data.name);
employee_title.setValue(employee_data.getAt(0).data.title);
employee_hire_date.setValue(employee_data.getAt(0).data.hire_date);
employee_active.setValue(Ext.util.Format.boolean(employee_data.getAt(0).data.active));
 我们要创徏提交按钮q添加到表单Q记得给来源于表单字D늚POST数据讑֮扩展参数。你会发现通过行确定字D(idQ对于让php脚本扑ֈ需要更新的行非常有用,同时Z更好的判断,q需要一个action判定?/p>


我还使用isValid参数来保证表单在提交前符合每一个字D늚要求?/p>


form_employee.addButton('Save', function(){
 if (form_employee.isValid()) {
  form_employee.submit({
   params:{
    action:'submit',
    id:employee_data.getAt(0).data.id
   },
   waitMsg:'Saving...'
  }); 
 }else{
  Ext.MessageBox.alert('Errors', 'Please fix the errors noted.');
 }
}, form_employee);

form_employee.render('employee-form');
 d我们的数?br>现在我们来读取数?/p>


employee_data.load();
 q样真的能够惊h单的创徏一个可用的表单Q与成对的服务器D脚本接合,p够将数据从数据库获取q写入修改后的数据。这些服务端脚本可以单到只需几行而已?/p>

接下来是什么?

通常来说QAPI文g和例子对于学习怎么样将表单攚w成你所需要的形式来说是很不错的途径?br>



菠萝 2007-08-07 14:04 发表评论
]]>
学习EXTW十?-模板QTemplatesQv?/title><link>http://m.tkk7.com/boluobn/articles/134946.html</link><dc:creator>菠萝</dc:creator><author>菠萝</author><pubDate>Tue, 07 Aug 2007 06:01:00 GMT</pubDate><guid>http://m.tkk7.com/boluobn/articles/134946.html</guid><wfw:comment>http://m.tkk7.com/boluobn/comments/134946.html</wfw:comment><comments>http://m.tkk7.com/boluobn/articles/134946.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://m.tkk7.com/boluobn/comments/commentRss/134946.html</wfw:commentRss><trackback:ping>http://m.tkk7.com/boluobn/services/trackbacks/134946.html</trackback:ping><description><![CDATA[<p>W一?(zhn)的HTML模板<br>W一个步骤没有Q何特别,q里的HTML可以说是用来格式化你的数据。花括号里面的关键字是你数据中的{id},{url} 和{text}的容器(placeholderQ?。或者用U数字{0},{1},{2}来表C?但是关键字的命名方式会你的代码更可诅R?/p> <p>现在我们加蝲html模板Q创Z个模板对象(W五行)Q然后进行编译(W六行)。尽编译模板不是必ȝQ但是一般情况下总能改善性能的?/p> <p><br> var html = '<a id="{id}" href="{url}" class="nav">{text}</a><br />';<br> var tpl =<br>        <br>    new Ext.Template(html);<br> tpl.compile();<br>W二步,数据加入到模板?br>q里我们用appendҎ(gu)加入两行的数据。正如你所见,元素?#8220;id”?#8220;url”?#8220;text”相对应于上述模板的容器?/p> <p><br> tpl.append('blog-roll', {<br>     id: 'link1', <br>     url: 'http://www.jackslocum.com/', <br>     text: "Jack's Site"<br> });<br> tpl.append('blog-roll', {<br>     id: 'link2', <br>     url: 'http://www.extjs.com/', <br>     text: "Jack's New Site"<br> });</p> <p>q就是模板的基本知识点,对于你来q说非常单吧Q?/p> <p>下一?br>如果你想换换口味Q文档区便是一个绝佳的好地斏V看看范例Feed ViewerQ里面就大量使用了模ѝ?</p> <p> </p> <img src ="http://m.tkk7.com/boluobn/aggbug/134946.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://m.tkk7.com/boluobn/" target="_blank">菠萝</a> 2007-08-07 14:01 <a href="http://m.tkk7.com/boluobn/articles/134946.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>学习EXTW十日(BQ:学习利用模板QTemplatesQ的格式化功?/title><link>http://m.tkk7.com/boluobn/articles/134942.html</link><dc:creator>菠萝</dc:creator><author>菠萝</author><pubDate>Tue, 07 Aug 2007 05:53:00 GMT</pubDate><guid>http://m.tkk7.com/boluobn/articles/134942.html</guid><wfw:comment>http://m.tkk7.com/boluobn/comments/134942.html</wfw:comment><comments>http://m.tkk7.com/boluobn/articles/134942.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://m.tkk7.com/boluobn/comments/commentRss/134942.html</wfw:commentRss><trackback:ping>http://m.tkk7.com/boluobn/services/trackbacks/134942.html</trackback:ping><description><![CDATA[<p>Summary摘要Q如何利用模板(TemplatesQ的格式化功能和加入(zhn)自定义格式的函?br>Author: Aaron Conran<br>Translater:Frank Cheung<br>Published: May 16, 2007</p> <p>本教E基于Ext的模板引擎展开详述Q亦是对 Shea Frederick“模板入门”教程一文的补充。假设读者已l初步接触过模板QTemplatesQ?和格式化函数的基本语法ؓ“{VARIABLE:[(可选的参数)]}”?</p> <p><br>正式开?br>假设我们打算从一变量中, 打印出内容,但当中的内容有可能会占用q多的空间。对于这U情况,通过的办法是对该内容截取Q限制在50个英文字W内Q然后做成连接让用户点击后观察全文。函?ellipsis" 的功能正是这P可限制在L字符数内。另外,在截取字W串的后面,该函数还会加?#8220;...“Q以C实际的内容q有更多?</p> <p>一个模板如下示Q?/p> <p> </p> <p>var myTpl = new Ext.Template('<div>{content:ellipsis(50)}<br/><a href="{moreLink}">Read More</a></div>');<br> 通过处理Q其中有47个字W是属于内容本n的,另外三个字符?#8221;...“,一?0个字W?/p> <p>q是一份格式化函数的列表,可用于模板:<br>ellipsis(length) - 对大于指定长度部分的字符Ԍq行裁剪Q增加省略号Q?#8220;...”Q的昄。适用于只昄前N位的字符Q然后提供详l页面的场合?<br>undef -查一个值是否ؓunderfinedQ如果是的{换ؓI?<br>htmlEncode - 转换(&, <, >, and ') 字符 <br>trim - 对一D|本的前后多余的空D?<br>substr(start, length) - q回一个从指定位置开始的指定长度的子字符丌Ӏ?<br>lowercase - q回一个字W串Q该字符串中的字母被转换为小写字母?<br>uppercase - q回一个字W串Q该字符串中的字母被转换为大写字母?<br>capitalize - q回一个字W串Q该字符串中的第一个字母{化ؓ大写字母Q剩余的为小写?<br>usMoney - 格式化数字到元货币。如Q?10.97 <br>date[(format)] - 一个日期解析成Z个特定格式模式的日期。如日期字符串不输入Q默认ؓ“??q?#8221; <br>stripTags - 剥去变量的所有HTML标签 </p> <p>(zhn)亦可以创徏自定义的格式化函敎ͼ具体做法是,在模板的实例上加入新的方法,l而在模板上调用,格式化的函数应该像这L(fng)Q?{VARIABLE:this.}"</p> <p>q是一个简单是实例Q对模板实例加入一?yesNoFormat "的新函数。yesNoFormat 与ColdFusion转换”truthy“函数相类?Q如果是真的输出"Yes",假的输出”No“?/p> <p><br>var testCustomTpl = new Ext.Template('<div>User: {username} IsRevoked: {revoked:this.yesNoFormat}</div>');<br>testCustomTpl.yesNoFormat = function(value) {<br> return value ? 'Yes' : 'No';<br>};  <br>testCustomTpl.append(document.body, {username: 'aconran', revoked: 1});   <br>  下一?br>关于怎么学好EXTq个框架我的看法是,在?zhn)熟(zhn)的IDE中打开源码q行阅读。保证阁下一定会收获不少技巧和写代码的好习惯,而且极有可能发现新的大陆Q还是没有归的。熟(zhn)模板Templates的简单用法和格式化功能后Q就可进入下一步的学习QMasterTemplates。MasterTemplates提供了处?#8221;子模?#8220;的功能,以方便从数据库@环数据,同时亦包含模板(TemplatesQ的所有功能?/p> <p> </p> <img src ="http://m.tkk7.com/boluobn/aggbug/134942.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://m.tkk7.com/boluobn/" target="_blank">菠萝</a> 2007-08-07 13:53 <a href="http://m.tkk7.com/boluobn/articles/134942.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss> <footer> <div class="friendship-link"> <p>лǵվܻԴȤ</p> <a href="http://m.tkk7.com/" title="亚洲av成人片在线观看">亚洲av成人片在线观看</a> <div class="friend-links"> </div> </div> </footer> վ֩ģ壺 <a href="http://323c.com" target="_blank">޵һƵ߹ۿ</a>| <a href="http://avdian126.com" target="_blank">Ʒþþþþù</a>| <a href="http://5d8f.com" target="_blank">ɫͼУ԰ɫ</a>| <a href="http://8953y.com" target="_blank">AVר߲</a>| <a href="http://by7258.com" target="_blank">Ʒ޸һ</a>| <a href="http://ivy-fund.com" target="_blank">޹߹ۿ</a>| <a href="http://alodaba.com" target="_blank">޹Ʒ߹ۿ</a>| <a href="http://www026qqcom.com" target="_blank">av߹ۿҰ</a>| <a href="http://fcw70.com" target="_blank">޳aһ </a>| <a href="http://jinlaifubuxiugang.com" target="_blank">avרԭ</a>| <a href="http://kkjk123.com" target="_blank">ɫAVպ߹ۿ</a>| <a href="http://6711wan.com" target="_blank">޾Һվ</a>| <a href="http://xy996688.com" target="_blank">ɫվwwwþþ</a>| <a href="http://jlzjjy.com" target="_blank">ղƷһ</a>| <a href="http://dfcnpc.com" target="_blank">aר߹ۿɫ </a>| <a href="http://16688shop.com" target="_blank">Ļ޾Ʒ</a>| <a href="http://88bgbg.com" target="_blank">˳վ18ֹ</a>| <a href="http://zhaosaohuo.com" target="_blank">Ƶһ</a>| <a href="http://ziniurj.com" target="_blank">պëƬƵѿ</a>| <a href="http://nuosheying.com" target="_blank">޳a߹ۿ</a>| <a href="http://am33318.com" target="_blank">Ƶ߹ۿƵ</a>| <a href="http://ocn888.com" target="_blank">þþƷAVDz18</a>| <a href="http://yuanzhouxh.com" target="_blank">ƷŮߵӰ </a>| <a href="http://010youhua.com" target="_blank">Ѵվ߿</a>| <a href="http://kanzhelu23.com" target="_blank">պ޵һҳ</a>| <a href="http://1992zyzp.com" target="_blank">޹Ʒþþ</a>| <a href="http://plladay.com" target="_blank">޾Ʒר91</a>| <a href="http://zhuguangbaoyu.com" target="_blank">avttֻ</a>| <a href="http://778002.com" target="_blank">޾ƷŮþþ</a>| <a href="http://477077.com" target="_blank">ߵӰ</a>| <a href="http://6000cpkj.com" target="_blank">˳ɵӰվþ</a>| <a href="http://pecbj.com" target="_blank">ѳ̱߸߳Ƶ </a>| <a href="http://wwwee2.com" target="_blank">Ʒ޹</a>| <a href="http://65123456.com" target="_blank">պav</a>| <a href="http://yzddcpj.com" target="_blank">һëƬڵȫ</a>| <a href="http://01shanzhai.com" target="_blank">ɫƷվ</a>| <a href="http://pc521.com" target="_blank">ؼëƬAëƬѲ</a>| <a href="http://sdzntg.com" target="_blank">һƷһAVһ</a>| <a href="http://cnepu.com" target="_blank">һ߹ۿѸ߹ۿ</a>| <a href="http://qixiresort.com" target="_blank">ŷһëƬ</a>| <a href="http://0147222.com" target="_blank">޾Ʒ</a>| <script> (function(){ var bp = document.createElement('script'); var curProtocol = window.location.protocol.split(':')[0]; if (curProtocol === 'https') { bp.src = 'https://zz.bdstatic.com/linksubmit/push.js'; } else { bp.src = 'http://push.zhanzhang.baidu.com/push.js'; } var s = document.getElementsByTagName("script")[0]; s.parentNode.insertBefore(bp, s); })(); </script> </body>