dojo 官方翻译 dojo/Deferred
延迟,异步调用
官网地址:http://dojotoolkit.org/reference-guide/1.9/dojo/Deferred.html
require(["dojo/Deferred", "dojo/dom", "dojo/on", "dojo/domReady!"],
function(Deferred, dom, on){
function asyncProcess(){
var deferred = new Deferred(); dom.byId("output").innerHTML = "I'm running..."; setTimeout(function(){
deferred.resolve("success");
}, 1000); return deferred.promise;
} on(dom.byId("startButton"), "click", function(){
var process = asyncProcess();
process.then(function(results){
dom.byId("output").innerHTML = "I'm finished, and the result was: " + results;
});
}); });
链式调用
require(["dojo/Deferred", "dojo/dom", "dojo/on", "dojo/domReady!"],
function(Deferred, dom, on){
function asyncProcess(msg){
var deferred = new Deferred(); dom.byId("output").innerHTML += "<br/>I'm running..."; setTimeout(function(){
deferred.resolve(msg);
}, 1000); return deferred.promise;
} on(dom.byId("startButton"), "click", function(){
var process = asyncProcess("first");
process.then(function(results){
dom.byId("output").innerHTML += "<br/>I'm finished, and the result was: " + results;
return asyncProcess("second");
}).then(function(results){
dom.byId("output").innerHTML += "<br/>I'm really finished now, and the result was: " + results;
});
}); });
reject
require(["dojo/Deferred", "dojo/dom", "dojo/on", "dojo/domReady!"],
function(Deferred, dom, on){
function asyncProcess(msg){
var deferred = new Deferred(); dom.byId("output").innerHTML += "<br/>I'm running..."; setTimeout(function(){
deferred.progress("halfway");
}, 1000); setTimeout(function(){
deferred.resolve("finished");
}, 2000); setTimeout(function(){
deferred.reject("ooops");
}, 1500); return deferred.promise;
} on(dom.byId("startButton"), "click", function(){
var process = asyncProcess();
process.then(function(results){
dom.byId("output").innerHTML += "<br/>I'm finished, and the result was: " + results;
}, function(err){
dom.byId("output").innerHTML += "<br/>I errored out with: " + err;
}, function(progress){
dom.byId("output").innerHTML += "<br/>I made some progress: " + progress;
});
});
cancel
require(["dojo/Deferred", "dojo/dom", "dojo/on", "dojo/domReady!"],
function(Deferred, dom, on){
function asyncProcess(){
var timeout;
var deferred = new Deferred(function(reason){
clearTimeout(timeout);
dom.byId("output").innerHTML += "<br/>I was cancelled with reason: " + reason;
}); dom.byId("output").innerHTML += "<br/>I'm running..."; timeout = setTimeout(function(){
dom.byId("output").innerHTML += "<br/>My process completed!";
deferred.resolve("finished");
}, 2000); return deferred.promise;
} on(dom.byId("startButton"), "click", function(){
var process = asyncProcess();
process.then(function(results){
dom.byId("output").innerHTML += "<br/>I'm finished, and the result was: " + results;
}); setTimeout(function(){
process.cancel("goodbye");
}, 1000);
}); });
dojo 官方翻译 dojo/Deferred的更多相关文章
- dojo 官方翻译 dojo/aspect
官网地址:http://dojotoolkit.org/reference-guide/1.10/dojo/aspect.html after() 定义:after(target, methodNam ...
- dojo 官方翻译 dojo/_base/lang 版本1.10
官方地址:http://dojotoolkit.org/reference-guide/1.10/dojo/_base/lang.html#dojo-base-lang 应用加载声明: require ...
- dojo 官方翻译 dojo/_base/array 版本1.10
官方地址:http://dojotoolkit.org/reference-guide/1.10/dojo/_base/array.html#dojo-base-array array模块dojo进行 ...
- dojo 官方翻译 dojo/domReady 版本1.10
官方地址:http://dojotoolkit.org/reference-guide/1.10/dojo/domReady.html#dojo-domready dom加载完成后,执行. requi ...
- dojo 官方翻译 dojo/json 版本1.10
官方地址:http://dojotoolkit.org/reference-guide/1.10/dojo/json.html#dojo-json require(["dojo/json&q ...
- dojo 官方翻译 dojo/string 版本1.10
官方地址:http://dojotoolkit.org/reference-guide/1.10/dojo/string.html#dojo-string require(["dojo/st ...
- DOJO官方API翻译或解读-dojo/store (自定制存储器)
dojo/store 是对已存数据的访问和存储的统一接口,dojo/store意图以一个简单.易于使用和扩展的API来,替代.集合和改善 dojo/data 和dojox/storage .基于HTM ...
- 现代DOJO(翻译)
http://dojotoolkit.org/documentation/tutorials/1.10/modern_dojo/index.html 你可能已经不用doio一段时间了,或者你一直想保持 ...
- Events with Dojo(翻译)
In this tutorial, we will be exploring dojo/on and how Dojo makes it easy to connect to DOM events. ...
随机推荐
- 从以下哪一个选项中可以获得Servlet的初始化参数。
从以下哪一个选项中可以获得Servlet的初始化参数. A.Servlet B.ServletContext C.ServletConfig D.GenericServlet 解答:C servlet ...
- java算法-数学之美一
巧用数学的思想来解决程序算法问题,这样的代码如诗般优美.通过数学思想来看问题,也能将程序简单化.“斐波那契数列”对于java程序员来说一定不陌生.当然这个问题的解决方案也有很多.用一个例子说明数学思想 ...
- Ubuntu上安装与配置JDK1.8
Ubuntu上安装与配置JDK1.8 一.下载 下载JDK,由于是Ubuntu. 所以去官网下载tar.gz格式的就可以(ubuntu使用浏览器下载网速比較慢,所以推荐到window上下载好). ht ...
- poj 3308(最小点权覆盖、最小割)
题目链接:http://poj.org/problem?id=3308 思路:裸的最小点权覆盖,建立超级源点和超级汇点,将源点与行相连,容量为这行消灭敌人的代价,将列与汇点相连,容量为这列消灭敌人的代 ...
- python 保存csv文件
利用pandas库, 将numpy的array数据保存成csv格式的文件: import pandas as pd import numpy as np data = pd.read_csv('C:\ ...
- selenium 方法导图
- Linux ssh其他服务器
- Jmeter--BeanShell使用
博客首页:http://www.cnblogs.com/fqfanqi/ (一)BeanShell简介 BeanShell是一个小型嵌入式Java源代码解释器,具有对象脚本语言特性,能够动态地执行标准 ...
- Jupyter Notebook远程服务器配置
首先要生成密码,打开python终端. In [1]: from IPython.lib import passwd In [2]: passwd() Enter password: Verify p ...
- Linux磁盘分区的理解
磁盘分割: 一块磁盘可以被分割为多个分区artition. 磁盘链接的方式 正常的实体机使用的都是/dev/sd[a-]的硬盘档名 虚拟机可能会使用/dev/vd[a-p]这种装置档名 SATA/US ...