本文整理匯總了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();
}