﻿<?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-Burn Net--烧网-随笔分类-Dojo</title><link>http://www.blogjava.net/burnet/category/12422.html</link><description>玩的是电脑，别被电脑玩了。</description><language>zh-cn</language><lastBuildDate>Fri, 02 Mar 2007 05:12:36 GMT</lastBuildDate><pubDate>Fri, 02 Mar 2007 05:12:36 GMT</pubDate><ttl>60</ttl><item><title>Dojo book第一章补充 I/O </title><link>http://www.blogjava.net/burnet/archive/2006/06/27/55339.html</link><dc:creator>Burn Net</dc:creator><author>Burn Net</author><pubDate>Tue, 27 Jun 2006 08:56:00 GMT</pubDate><guid>http://www.blogjava.net/burnet/archive/2006/06/27/55339.html</guid><wfw:comment>http://www.blogjava.net/burnet/comments/55339.html</wfw:comment><comments>http://www.blogjava.net/burnet/archive/2006/06/27/55339.html#Feedback</comments><slash:comments>6</slash:comments><wfw:commentRss>http://www.blogjava.net/burnet/comments/commentRss/55339.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/burnet/services/trackbacks/55339.html</trackback:ping><description><![CDATA[译者序：<br />Dojo book目前还在不断更新和补充中，我会尽量跟上原著的脚步，给大家最新的信息。<br />更新我会用随笔写出来，同时也会更新原文章。<br /><hr size="2" width="100%" /><b>I/O<br /><br />dojo.io.blind介绍</b><br /><br />在我们制作dojo的时候，目的是让用户和开发者都能享受到DHTML程序。在很多朋友的支持下，特别是Aaron
Boodman和Mark Anderson，我们已经找到了解决可用性的方法。我们提供了一个单独的易用的API和一个包装类，这个类只需要两个文件。dojo.io包提供了对XMLHTTP和一些其他更复杂的传输结构的支持。<br /><br />在dojo.io包中我们一般最常使用的是dojo.io.bind()方法。dojo.io.blind()是一个标准的异步的请求API，它包含了各种传输层（transport layers），包括queues of iFrames,XMLHTTP,mod_pubsub,LivePage等等。Dojo会试图为当前的请求选择最合适的传输方法，因为在做网站时一般不会使用到其他传输，所以我们只用到XMLHTTP。dojo接受一个匿名的类，但是在知道这个类的属性的情况下，把它作为方法参数（function argument）。下面的代码是创建一个请求（request），这个请求会从URL返回原始的字符串。<br /><div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; background-color: rgb(238, 238, 238); font-size: 13px; width: 98%;"><!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>--><span style="color: rgb(0, 0, 0);">dojo.io.bind({<br />    url: </span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">http://foo.bar.com/sampleData.txt</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">,<br />    load: </span><span style="color: rgb(0, 0, 255);">function</span><span style="color: rgb(0, 0, 0);">(type, data, evt){ </span><span style="color: rgb(0, 128, 0);">/*</span><span style="color: rgb(0, 128, 0);">do something w/ the data </span><span style="color: rgb(0, 128, 0);">*/</span><span style="color: rgb(0, 0, 0);"> },<br />    mimetype: </span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">text/plain</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);"><br />});</span></div><br />这就是全部，你提供了一个数据地址，还有一个当你得到返回值时要执行的function。但是如果在请求过程中出错了怎么办呢？我们再来创建一个register来解决：<br /><br /><div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; background-color: rgb(238, 238, 238); font-size: 13px; width: 98%;"><!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>--><span style="color: rgb(0, 0, 0);">dojo.io.bind({<br />    url: </span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">http://foo.bar.com/sampleData.txt</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">,<br />    load: </span><span style="color: rgb(0, 0, 255);">function</span><span style="color: rgb(0, 0, 0);">(type, data, evt){ </span><span style="color: rgb(0, 128, 0);">/*</span><span style="color: rgb(0, 128, 0);">do something w/ the data </span><span style="color: rgb(0, 128, 0);">*/</span><span style="color: rgb(0, 0, 0);"> },<br />    error: </span><span style="color: rgb(0, 0, 255);">function</span><span style="color: rgb(0, 0, 0);">(type, error){ </span><span style="color: rgb(0, 128, 0);">/*</span><span style="color: rgb(0, 128, 0);">do something w/ the error</span><span style="color: rgb(0, 128, 0);">*/</span><span style="color: rgb(0, 0, 0);"> },<br />    mimetype: </span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">text/plain</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);"><br />});</span></div><br />同样也可以只创建一个单独的handler来解决：<br /><div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; background-color: rgb(238, 238, 238); font-size: 13px; width: 98%;"><!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>--><span style="color: rgb(0, 0, 0);">dojo.io.bind({<br />    url: </span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">http://foo.bar.com/sampleData.txt</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">,<br />    handle: </span><span style="color: rgb(0, 0, 255);">function</span><span style="color: rgb(0, 0, 0);">(type, data, evt){<br />        </span><span style="color: rgb(0, 0, 255);">if</span><span style="color: rgb(0, 0, 0);">(type </span><span style="color: rgb(0, 0, 0);">==</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">load</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">){<br />            </span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);"> do something with the data object</span><span style="color: rgb(0, 128, 0);"><br /></span><span style="color: rgb(0, 0, 0);">        }</span><span style="color: rgb(0, 0, 255);">else</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">if</span><span style="color: rgb(0, 0, 0);">(type </span><span style="color: rgb(0, 0, 0);">==</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">error</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">){<br />            </span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);"> here, "data" is our error object</span><span style="color: rgb(0, 128, 0);"><br /></span><span style="color: rgb(0, 0, 0);">            </span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);"> respond to the error here</span><span style="color: rgb(0, 128, 0);"><br /></span><span style="color: rgb(0, 0, 0);">        }</span><span style="color: rgb(0, 0, 255);">else</span><span style="color: rgb(0, 0, 0);">{<br />            </span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);"> other types of events might get passed, handle them here</span><span style="color: rgb(0, 128, 0);"><br /></span><span style="color: rgb(0, 0, 0);">        }<br />    },<br />    mimetype: </span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">text/plain</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);"><br />});</span></div><br />下面的代码提交一段javascript程序段，然后让服务器运行它，一般我们这么做是为了加速程序运行，注意<u>mimetype：<br /></u><div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; background-color: rgb(238, 238, 238); font-size: 13px; width: 98%;"><!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>--><span style="color: rgb(0, 0, 0);">dojo.io.bind({<br />    url: </span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">http://foo.bar.com/sampleData.js</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">,<br />    load: </span><span style="color: rgb(0, 0, 255);">function</span><span style="color: rgb(0, 0, 0);">(type, evaldObj){ </span><span style="color: rgb(0, 128, 0);">/*</span><span style="color: rgb(0, 128, 0);"> do something </span><span style="color: rgb(0, 128, 0);">*/</span><span style="color: rgb(0, 0, 0);"> },<br />    mimetype: </span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">text/javascript</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);"><br />});</span></div><u><br /></u>如果你想确保程序使用XMLHTTP，可以这样写：<br /><div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; background-color: rgb(238, 238, 238); font-size: 13px; width: 98%;"><!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>--><span style="color: rgb(0, 0, 0);">dojo.io.bind({<br />    url: </span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">http://foo.bar.com/sampleData.js</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">,<br />    load: </span><span style="color: rgb(0, 0, 255);">function</span><span style="color: rgb(0, 0, 0);">(type, evaldObj){ </span><span style="color: rgb(0, 128, 0);">/*</span><span style="color: rgb(0, 128, 0);"> do something </span><span style="color: rgb(0, 128, 0);">*/</span><span style="color: rgb(0, 0, 0);"> },<br />    mimetype: </span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">text/plain</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">, </span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);"> get plain text, don't eval()</span><span style="color: rgb(0, 128, 0);"><br /></span><span style="color: rgb(0, 0, 0);">    transport: </span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">XMLHTTPTransport</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);"><br />});</span></div>Being a jack-of-all-trades, <tt class="docutils literal"><span class="pre">bind()</span></tt> also supports the submission of forms via a
request (with the single caveat that it won't do file upload over XMLHTTP):<br />作为一个jack-of-all-trades（万事通），bind()同样支持来自于表单提交的数据。<br /><div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; background-color: rgb(238, 238, 238); font-size: 13px; width: 98%;"><!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>--><span style="color: rgb(0, 0, 0);">dojo.io.bind({<br />    url: </span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">http://foo.bar.com/processForm.cgi</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">,<br />    load: </span><span style="color: rgb(0, 0, 255);">function</span><span style="color: rgb(0, 0, 0);">(type, evaldObj){ </span><span style="color: rgb(0, 128, 0);">/*</span><span style="color: rgb(0, 128, 0);"> do something </span><span style="color: rgb(0, 128, 0);">*/</span><span style="color: rgb(0, 0, 0);"> },<br />    formNode: document.getElementById(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">formToSubmit</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">)<br />});</span></div>以上只是一些最基本的，其实这些可以不用全部由开发者自定义。<br /><br /><b>RPC</b><br />你可以看到，Dojo通过dojo.io.bind提供了简单，强大的方法使用多种多样的I/O functions。但是在开发过程中，程序员会调用很多很多I/O，这同时会给服务器和客户端加重负担。Dojo的RPC服务就是为了减少负担，易用，精简代码而生的。<br /><br />RPC的全名是Remote Procedre Calls,或者Remote Method Invocation,（译者：远程method调用）。最基本的，RPC允许开发者调用在远程服务器上的方法（method）。Dojo不仅提供了基本的RPC client包，而且还扩展了它，使它支持JSON-RPC服务和YAHOO服务。同时你也可以自己写出相对于其他服务的类。<br /><br />我们假定有一个需要调用服务器端程序的小程序，假设要调用add(x,y)和subtract(x,y)。在没有特殊情况的条件下，我们的客户端会这样写：<br /><div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; background-color: rgb(238, 238, 238); font-size: 13px; width: 98%;"><!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>--><span style="color: rgb(0, 0, 0);">add </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">function</span><span style="color: rgb(0, 0, 0);">(x,y) {<br /><br />    request </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> {x: x, y: y};<br /><br />    dojo.io.bind({<br />            url: </span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">add.php</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">,<br />            load: onAddResults,<br />            mimetype: </span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">text/plain</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">,<br />        content: request<br />    });<br />}<br /><br />subtract </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">function</span><span style="color: rgb(0, 0, 0);">(x,y) {<br /><br />    request </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> {x: x, y: y};<br />    <br />    dojo.io.bind({<br />            url: </span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">subract</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">,<br />            load: onSubtractResults,<br />            mimetype: </span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">text/plain</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);"><br />        content: request<br />    });<br />}</span></div><br /><img src="file:///C:/DOCUME%7E1/user/LOCALS%7E1/Temp/moz-screenshot.jpg" alt="" /><br />你看，这不是很难。但是无论是我们让服务器运行add和subtract还是让客户端自己计算，这只是一个非常简单的程序。如果我们要调用在服务器上30个不同method会怎么样呢？我猜我们可能要重复的写几乎一样的代码一遍又一遍，每次都要创建一个请求类（request object),设定URL，设定变量等等。这不仅容易出错，而且还很枯燥。<br />Dojo的RPC客户端简化了这个过程：<p></p><div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; background-color: rgb(238, 238, 238); font-size: 13px; width: 98%;"><!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>--><span style="color: rgb(0, 0, 0);">{<br />    </span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">serviceType</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">: </span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">JSON-RPC</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">, <br />    </span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">serviceURL</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">: </span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">rpcProcessor.php</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">, <br />    </span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">methods</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">:[ <br />        {<br />            </span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">name</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">: </span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">add</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">, <br />            </span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">parameters</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">:[<br />                {</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">name</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">: </span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">x</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">},<br />                {</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">name</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">: </span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">y</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">}    <br />            ]<br />        },<br />        {<br />            </span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">name</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">: </span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">subtract</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">, <br />            </span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">parameters</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">:[<br />                {</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">name</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">: </span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">x</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">},<br />                {</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">name</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">: </span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">y</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">}    <br />            ]<br />        }<br /><br />    ]<br />}</span></div><br />以上就是对于服务器的定义。一旦定义创建完毕，其他的事情就简单了，我们还可以创建一个类：<br /><div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; background-color: rgb(238, 238, 238); font-size: 13px; width: 98%;"><!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>--><span style="color: rgb(0, 0, 255);">var</span><span style="color: rgb(0, 0, 0);"> myObject </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">new</span><span style="color: rgb(0, 0, 0);"> dojo.rpc.JsonService</span><span style="color: rgb(0, 0, 0);">?</span><span style="color: rgb(0, 0, 0);">(defintion);</span></div>要使用服务器的方法：<br /><div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; background-color: rgb(238, 238, 238); font-size: 13px; width: 98%;"><!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>--><span style="color: rgb(0, 0, 0);">myObject.add(</span><span style="color: rgb(0, 0, 0);">3</span><span style="color: rgb(0, 0, 0);">,</span><span style="color: rgb(0, 0, 0);">5</span><span style="color: rgb(0, 0, 0);">);</span></div><br />我敢打赌你会在想“我不是只调用方法就够了，我还有得到计算的结果。”你是对的，但这也是非常容易的。服务器端的myObject.add()会返回一个延缓类（deferred object）。Twisted Python用户可能对延缓类（deferred object）很熟悉，延缓类（deferred object）允许开发者根据返回数据的类型附加一个或更多的回叫（callbacks）和错误处理（errbacks）。这里有一个简单的例子：<br /><div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; background-color: rgb(238, 238, 238); font-size: 13px; width: 98%;"><!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>--><span style="color: rgb(0, 0, 255);">var</span><span style="color: rgb(0, 0, 0);"> myDeferred </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> myObject.add(</span><span style="color: rgb(0, 0, 0);">3</span><span style="color: rgb(0, 0, 0);">,</span><span style="color: rgb(0, 0, 0);">5</span><span style="color: rgb(0, 0, 0);">);<br />myDeferred.addCallback(myCallbackMethod);</span></div><br />我们把mycallbackmethod作为回叫添加到我们的延缓类mydeferred。这时，8会被传递进mycallbackmethod。另一方面，我们也可以添加一个errback method来处理服务器返回的出错信息。我们随意添加回叫方法（callback），多少都可以，它们会按照我们定义的顺序被调用。<br /><br />以上的例子都是围绕dojo.rpc.JsonService展开的。我们还可以使用dojo.rpc.YahooService，规范和结构都是一样的。这两个类都是继承了dojo.rpc.RpcService。要创建自己的类会在第二章中详细介绍。（译者：第二章原著还没有完成）<br /><img src ="http://www.blogjava.net/burnet/aggbug/55339.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/burnet/" target="_blank">Burn Net</a> 2006-06-27 16:56 <a href="http://www.blogjava.net/burnet/archive/2006/06/27/55339.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>最近爱上Dojo</title><link>http://www.blogjava.net/burnet/archive/2006/06/22/54564.html</link><dc:creator>Burn Net</dc:creator><author>Burn Net</author><pubDate>Thu, 22 Jun 2006 11:10:00 GMT</pubDate><guid>http://www.blogjava.net/burnet/archive/2006/06/22/54564.html</guid><wfw:comment>http://www.blogjava.net/burnet/comments/54564.html</wfw:comment><comments>http://www.blogjava.net/burnet/archive/2006/06/22/54564.html#Feedback</comments><slash:comments>1</slash:comments><wfw:commentRss>http://www.blogjava.net/burnet/comments/commentRss/54564.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/burnet/services/trackbacks/54564.html</trackback:ping><description><![CDATA[也许是因为Dojo的简洁，强大，或者是我真的没有耐心自己一点一点写javascript。<br /><br />以前研究过gwt，dwr，最后还是感觉dojo用得最舒服，dojo不会象dwr限制我的server side。<br /><br />以后我会写很多关于dojo的文章，当然还包括如何自由使用dojo链接到servlet/jsp/php/sql。<img src ="http://www.blogjava.net/burnet/aggbug/54564.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/burnet/" target="_blank">Burn Net</a> 2006-06-22 19:10 <a href="http://www.blogjava.net/burnet/archive/2006/06/22/54564.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>