本文整理匯總了TypeScript中d3-request.json函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript json函數的具體用法?TypeScript json怎麽用?TypeScript json使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了json函數的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: json
function json(innertext:string, sub: Element, url: string, fn: (data: any) => void) {
let i = document.createElement('i');
i.classList.add("loading");
i.classList.add("fa");
i.classList.add("fa-spinner");
i.classList.add("fa-pulse");
sub.innerHTML = "";
sub.appendChild(i);
(sub as any).onclick = function() {
json(innertext, sub, url, fn);
}
d3_json(url, (error: any, data: any) => {
if (error) {
i.classList.remove("fa-spinner");
i.classList.remove("fa-pulse");
i.classList.add("fa-refresh");
i.classList.add("connection-error");
let text = document.createElement('span');
text.classList.add("error-text")
text.innerHTML = innertext;
i.appendChild(text);
} else {
(sub as any).onclick = function() {
}
fn(data);
}
});
}
示例2: Promise
this._initPromise = new Promise((resolve, reject) => {
if (usCounties) {
resolve(usCounties);
}
d3Json(`${topoJsonFolder()}/us-counties.json`, function (_usCounties) {
usCounties = _usCounties;
resolve(usCounties);
});
}).then((usCounties: any) => {
示例3: d3Json
d3Json(`${topoJsonFolder()}/${context.region()}.json`, function (region) {
context._choroTopology = region;
context._choroTopologyObjects = region.objects.PolbndA;
context._choroTopologyFeatures = topojson.feature(context._choroTopology, context._choroTopologyObjects).features;
d3Json(`${topoJsonFolder()}/${context.region()}_idx.json`, indexLoad)
.on("error", function (err) {
indexLoad({});
})
;
function indexLoad(index) {
context._choroTopologyIndex = index;
resolve();
}
});
示例4: Promise
this._initPromise = new Promise((resolve, reject) => {
if (usCounties) {
resolve();
}
d3Json(`${topoJsonFolder()}/us-counties.json`, function (_usCounties) {
usCounties = _usCounties;
features = topojson.feature(usCounties.topology, usCounties.topology.objects.counties).features;
rFeatures = {};
for (const key in features) {
if (features[key].id) {
rFeatures[features[key].id] = features[key];
}
}
resolve();
});
});
示例5: function
// HTML Request
// -------------------------------------------------------------------------------
const html: d3Request.Request = d3Request.html(url);
const htmlWithCallback: d3Request.Request = d3Request.html(url, function(error, data) {
const that: d3Request.Request = this;
const err: any = error;
const d: DocumentFragment = data;
console.log(d);
});
// -------------------------------------------------------------------------------
// JSON Request
// -------------------------------------------------------------------------------
const json: d3Request.Request = d3Request.json(url);
const jsonWithCallback: d3Request.Request = d3Request.json<ResponseDatumGET[]>(url, function(error, data) {
const that: d3Request.Request = this;
const err: any = error;
const d: ResponseDatumGET[] = data;
console.log(d);
});
// -------------------------------------------------------------------------------
// Text Request
// -------------------------------------------------------------------------------
const text: d3Request.Request = d3Request.text(url);
const textWithCallback: d3Request.Request = d3Request.text(url, function(error, data) {
const that: d3Request.Request = this;
const err: any = error;
示例6: Promise
return new Promise((res, rej) => {
json(`http://localhost:5000/api/infographics/${this._query.country}/${this._query.graph}`, (data) => {
res(data);
});
})