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 EasyUI,Spinner(微调)组件
jQuery EasyUI,Spinner(微调)组件 学习要点: 1.加载方式 2.属性列表 3.事件列表 4.方法列表 本节课重点了解 EasyUI 中 Spinner(微调)组件的使用方法,这个 ...
- 说明Oracle数据库逻辑备份和物理备份的方式。
说明Oracle数据库逻辑备份和物理备份的方式. 解答:Oracle备份包括逻辑备份和物理备份. 1).逻辑备份 数据库的逻辑备份包含读一个数据库记录集和将记录集写入文件. a.输出(Export)输 ...
- mysql DBA 指南
Mysql目录 数据库介绍.常见分类 Mysql入门 Mysql安装配置 Mysql多实例安装配置 Mysql常用基本命令 Mysql权限体系 Mysql数据库备份和恢复 Mysql日志 Mysql逻 ...
- improve deep learning network 课程笔记
公开课笔记 Bias & variance bias: 1. more epoch 2. deeper network 3.hyperparameters variance : larger ...
- reactjs中props和state最佳实践
http://blog.csdn.net/dangnian/article/details/50998981
- 使用 Visual Studio 2015 编译 QT 工程
简单进行一下几步就可以了 1.下载源代码 qt-everywhere-opensource-src-5.6.0-alpha.7z .解压到 D:\ToolKits\5.6.0\src 目录下2.网站 ...
- UIWebview打开.txt文件中文乱码解决
用UIWebview打开txt文件有时候会出现乱码的情况,这种情况应该是txt的编码问题,解决方案如下: txt分带编码和不带编码两种,带编码的如UTF-8格式txt,不带编码的如ANSI格式txt. ...
- delphi 快捷键的使用
CTRL+SPACE 代码补全,很好用的(先改了输入法热键)CTRL+SHIFT+C 编写申明或者补上函数CTRL+SHIFT+↑(↓) 在过程.函数.事件内部, 可跳跃到相应的过程.函数.事件的定义 ...
- JZOJ.5279【NOIP2017模拟8.15】香港记者
Description
- jQuery Validation Engine 表单验证,自定义规则验证方法
jQuery Validation Engine 表单验证说明文档http://code.ciaoca.com/jquery/validation-engine/ js加到jquery.validat ...