本文整理汇总了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);
});
})