﻿<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"><channel><title>BlogJava-尘、封-文章分类-Extjs</title><link>http://www.blogjava.net/wzslw/category/51629.html</link><description>失败的尝试也胜过胎死腹中的策略。</description><language>zh-cn</language><lastBuildDate>Mon, 07 May 2012 05:38:32 GMT</lastBuildDate><pubDate>Mon, 07 May 2012 05:38:32 GMT</pubDate><ttl>60</ttl><item><title>EXT自定义事件</title><link>http://www.blogjava.net/wzslw/articles/377524.html</link><dc:creator>尘、封</dc:creator><author>尘、封</author><pubDate>Mon, 07 May 2012 05:23:00 GMT</pubDate><guid>http://www.blogjava.net/wzslw/articles/377524.html</guid><wfw:comment>http://www.blogjava.net/wzslw/comments/377524.html</wfw:comment><comments>http://www.blogjava.net/wzslw/articles/377524.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/wzslw/comments/commentRss/377524.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/wzslw/services/trackbacks/377524.html</trackback:ping><description><![CDATA[<p style="margin-left:18.0pt;text-indent:-18.0pt;">1．&nbsp;<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">创建用来触发事件的类</span></p>  <p style="margin-left:18.0pt"><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">如：</span><span style="font-size: 13px; color: #0000ff; ">var</span><span style="background-color: #eeeeee; font-size: 13px; ">&nbsp;Obj</span><span style="background-color: #eeeeee; font-size: 13px; ">=</span><span style="font-size: 13px; color: #0000ff; ">function</span><span style="background-color: #eeeeee; font-size: 13px; ">(){</span></p><div style="background-color:#eeeeee;font-size:13px;border:1px solid #CCCCCC;padding-right: 5px;padding-bottom: 4px;padding-left: 4px;padding-top: 4px;width: 98%;word-break:break-all">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000FF; ">this</span>.addEvents(&#8216;eat&#8217;);<span style="color: #008000; ">//</span><span style="color: #008000; ">添加自定义事件名称</span><span style="color: #008000; "><br /></span>}</div>  <p style="margin-left:21.0pt;text-indent:-21.0pt;">2.<span style="font-family: 'Times New Roman'; font-size: 7pt; line-height: normal; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">让类继承</span>Ext.util.Observable<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">类（只有继承该类的子类才可以有触发事件）</span></p>  <p style="margin-left:21.0pt"><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">如：</span></p><hr /><div style="background-color:#eeeeee;font-size:13px;border:1px solid #CCCCCC;padding-right: 5px;padding-bottom: 4px;padding-left: 4px;padding-top: 4px;width: 98%;word-break:break-all"><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />-->Ext.extend(Obj,Ext.util.Observable);</div>  <p style="margin-left:21.0pt;text-indent:-21.0pt;">3.<span style="font-family: 'Times New Roman'; font-size: 7pt; line-height: normal; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">创建实例</span></p>  <p style="margin-left:21.0pt"><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">如：</span><span style="font-size: 13px; color: #0000ff; ">var</span><span style="background-color: #eeeeee; font-size: 13px; ">&nbsp;object</span><span style="background-color: #eeeeee; font-size: 13px; ">=</span><span style="font-size: 13px; color: #0000ff; ">new</span><span style="background-color: #eeeeee; font-size: 13px; ">&nbsp;Obj();</span></p>  <p style="margin-left:21.0pt;text-indent:-21.0pt;">4.<span style="font-family: 'Times New Roman'; font-size: 7pt; line-height: normal; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">给实例绑定监听器</span></p>  <p style="margin-left:21.0pt"><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">如：</span><span style="background-color: #eeeeee; font-size: 13px; ">object.on(&#8216;eat&#8217;,</span><span style="font-size: 13px; color: #0000ff; ">function</span><span style="background-color: #eeeeee; font-size: 13px; ">(){</span></p><div style="background-color:#eeeeee;font-size:13px;border:1px solid #CCCCCC;padding-right: 5px;padding-bottom: 4px;padding-left: 4px;padding-top: 4px;width: 98%;word-break:break-all">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Ext.Msg.alert(&#8216;这是触发了eat&nbsp;事件的结果&#8217;);<br />});</div>  <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">注：此时</span>object.on()<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">等同于</span>object.addListener()</p>  <p style="margin-left:21.0pt;text-indent:-21.0pt;">5.<span style="font-family: 'Times New Roman'; font-size: 7pt; line-height: normal; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">事件触发</span></p>  <p style="margin-left:21.0pt"><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">如：</span><span style="background-color: #eeeeee; font-size: 13px; ">Ext.get(&#8216;btn&#8217;).on(&#8216;click&#8217;,</span><span style="font-size: 13px; color: #0000ff; ">function</span><span style="background-color: #eeeeee; font-size: 13px; ">(){</span></p><div style="background-color:#eeeeee;font-size:13px;border:1px solid #CCCCCC;padding-right: 5px;padding-bottom: 4px;padding-left: 4px;padding-top: 4px;width: 98%;word-break:break-all">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;object.fireEvent(&#8216;eat&#8217;);<br />})</div><img src ="http://www.blogjava.net/wzslw/aggbug/377524.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/wzslw/" target="_blank">尘、封</a> 2012-05-07 13:23 <a href="http://www.blogjava.net/wzslw/articles/377524.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>