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. ...
随机推荐
- jQuery多项选项卡的实现
请勿盗版.转载请加上出处http://blog.csdn.net/yanlintao1 请勿盗版,转载请加上出处http://blog.csdn.net/yanlintao1 css样式: @CHAR ...
- IdentityServer4环境部署失败分析贴(一)
前言: 在部署Idv4站点和其客户端在外网时,发现了许多问题,折腾了许久,翻看了许多代码,写个MD记录一下. 1.受保护站点提示错误: Unable to obtain configuration f ...
- 20个JS 小技巧超级实用
1. 将彻底屏蔽鼠标右键 oncontextmenu=”window.event.returnValue=false” < table border oncontextmenu=return(f ...
- 该如何将MathType公式粘贴到文档中
MathType是一款非常好用的数学公式编辑器,因为它与很多的文档处理器都能够很好地兼容,因此其使用范围非常的大.MathType公式编辑器编辑的公式与数学符号等都符号国际期刊的出版标准,并且上手容易 ...
- Ubuntu中su认证失败
Ubuntu安装后,root用户默认是被锁定了的,不允许登录,也不允许 su 到 root 解决方法 sudo -i,输入当前用户密码后以root权限登录shell,无时间限制.使用exit或logo ...
- CNN 各layer汇总
Flattening:类型为:Flatten 基于某个axis进行偏平的意思,如 axis = 1 ,fattens an input of shape n * c * h * w to a simp ...
- webpack 从入门到工程实践
from:https://www.jianshu.com/p/9349c30a6b3e?utm_campaign=maleskine&utm_content=note&utm_medi ...
- CGContextRef用法
本文转载至 http://blog.csdn.net/perfect_promise/article/details/7660220 quartz 是主要的描画接口,支持基于路径的描画. 抗锯齿渲染. ...
- HDU3308(LCIS) 线段树好题
题目链接:传送门 题目大意:给你n个数,m个操作.操作有两种:1.U x y 将数组第x位变为y 2. Q x y 问数组第x位到第y位连续最长子序列的长度.对于每次询问,输出一个答案 题目思路: ...
- 讨论cocos2d-x字体绘制原理和应用方案
转自:http://blog.csdn.net/langresser_king/article/details/9012789 个人一直认为,文字绘制是cocos2d-x最薄弱的环节.对于愤怒的小鸟之 ...