本文整理汇总了TypeScript中jQuery.Deferred函数的典型用法代码示例。如果您正苦于以下问题:TypeScript Deferred函数的具体用法?TypeScript Deferred怎么用?TypeScript Deferred使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Deferred函数的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: function
return function () {
var args = arguments;
var closure = function () {
return f.apply(undefined, args);
};
var d = $.Deferred();
pendingf = function () {
var exe = $.Deferred();
var cd = closure();
if (!cd || !$.isFunction(cd.always)) {
throw "Return value of wrapped function must be a deferred";
}
cd = cd.always(function () { exe.resolve(); });
pipeDeferred(cd, d);
return exe;
};
running = running.then(function () {
if (pendingf) {
var temp = pendingf;
pendingf = undefined;
return temp();
}
});
return d;
};
示例2: function
reject: function() {
let deferred = $.Deferred().reject()
let promise = deferred.promise()
attachImmediatelyRejectingThen(promise)
return promise
}
示例3: setTimeout
load_data: (frm: number, to: number) => {
console.error(`frm[${frm}] to[${to}]`)
let $deferred = $.Deferred<string[]>();
if (to > MAX_SIZE - 1) {
to = MAX_SIZE - 1;
}
setTimeout(() => {
$deferred.resolve(_.range(frm, to + 1).map((e) => `remote ${e}`));
}, 500);
return $deferred.promise();
}
示例4: getItem
getItem(id: number) {
var deferred = $.Deferred();
$.ajax({
type: "GET",
url: `${this.url}/${id}`,
contentType: "application/json; charset=utf-8",
dataType: "json",
success(data: T) {
return deferred.resolve(data);
},
error(msg: any) {
console.log("error calling service");
console.log(msg);
return deferred.reject(msg);
}
});
return deferred;
}
示例5: getVouchers
getVouchers() {
var deferred = $.Deferred();
$.ajax({
type: "GET",
url: "/assets/vouchers.json",
contentType: "application/json; charset=utf-8",
dataType: "json",
success(data: Voucher[]) {
return deferred.resolve(data);
},
error(msg: any) {
console.log("error calling service");
console.log(msg);
return deferred.reject(msg);
}
});
return deferred;
}
示例6: get
private static get() {
return $.Deferred(function() {
const deferred = this;
const jqXHR = $.ajax({
method: "GET",
url: Routes.apiv1LatestVersionInfoPath(),
timeout: mrequest.timeout,
beforeSend: mrequest.xhrConfig.forVersion("v1"),
contentType: false
});
const didFulfill = (data: LatestVersion) => {
deferred.resolve(data.latest_version);
};
const didReject = () => {
deferred.reject(null);
};
jqXHR.then(didFulfill, didReject);
}).promise();
}