本文整理匯總了TypeScript中csvtojson.Converter.fromFile方法的典型用法代碼示例。如果您正苦於以下問題:TypeScript Converter.fromFile方法的具體用法?TypeScript Converter.fromFile怎麽用?TypeScript Converter.fromFile使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類csvtojson.Converter
的用法示例。
在下文中一共展示了Converter.fromFile方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: Promise
new Promise((resolve, reject) => {
const converter = new Converter({});
converter.fromFile("./tests/tag.csv", (err, result) => {
if (err) {
console.log(err);
}
for (const row of result) {
let arr = [];
for (const key in row) {
if (row[key]) {
arr.push(row[key]);
}
}
if (arr.length > 0) tags.push(new Tag(arr));
}
resolve();
});
})
示例2: Converter
.then(() => {
const funcs:(() => Promise<void>)[] = [];
const converter = new Converter({});
let promise:any = Promise.resolve();
converter.fromFile("./tests/tagging.csv", (err, result) => {
for (const row of result) {
let arr = [];
for (const key in row) {
arr.push(row[key]);
}
promise = promise.then(() => data.tagging.addDummyByNames(arr[0], arr[1], arr[2]));
}
console.log(funcs.length);
});
/*
* Promise.allするのが理想だが、件數次第ではコネクションを待機件數が多すぎ、メモリを使い果たして死ぬ
* 仕方ないので一件一件放り込んでいく
*/
return promise;
})
示例3: TagGroup
return new Promise<TagGroup[]>((resolve, reject) => {
converter.fromFile("./tests/tagGroup.csv", (err, result) => {
const promises: Promise<TagGroup>[] = [];
if (err) console.log(err);
for (const row of result) {
if (!row['name']) continue;
let tagGroup: TagGroup = new TagGroup(row['name']);
let tagPromises = [];
for (const key in row) {
if (key == "name" || !row[key]) continue;
tagPromises.push(tagContainer.getByName(row[key]));
}
promises.push(
Promise.all<Tag>(tagPromises).then((tags:Tag[]) => {
tagGroup.member = tags;
console.log(tagGroup);
return Promise.resolve(tagGroup);
})
);
}
Promise.all<TagGroup>(promises)
.then(tagGroups2 => resolve(tagGroups2));
});
});