javascript - 如何从打字稿上的txt文件中获取数据?
问题描述
showFile() {
var fs = require('fs');
var obj = fs.readFile('dic.txt', 'utf8');
console.log(obj);
}
getItems(ev) {
// Reset items back to all of the items
this.initializeItems();
// set val to the value of the ev target
var val = ev.target.value;
// if the value is an empty string don't filter the items
if (val && val.trim() != '') {
this.items = this.items.filter((item) => {
this.showFile();
return (item.toLowerCase().indexOf(val.toLowerCase()) > -1);
})
}
}
我想制作一个移动应用程序作为字典。我有一个文本文件,其中存储了所有俄语单词和英语翻译。我需要从这个文件中进行搜索,何时输入单词并需要显示翻译。我正在 Ionic 3 上编写代码。我有错误:fs.readFile 不是函数。(在 'fs.readFile('dic.txt','utf8')','fs.readFile' 未定义)
解决方案
你可以读取一个json文件
import { HttpClient } from '@angular/common/http';
import { Observable } from 'rxjs/Observable';
constructor(private http: HttpClient) {
public getTranslation(): Observable<any> {
return this.http.get("./assets/translation.json")
}
}
推荐阅读
- python - math.floor() 和 // 产生不同的结果
- python - 如何在python中响应命令行提示符
- c# - LibGit2SharpException v0.26.0.0 - git fetch 暴露异常“重定向或身份验证重放私有存储库太多”
- kotlin - io.mockk.MockKException:找不到答案:SavedStateHandle(#1).set(Key, Something)
- common-lisp - 如何在 Lisp 的宏中修复“X 不是数字”
- python - 使用 sqlalchemy 和上下文管理器,数据库没有更新
- javascript - 角度变量错误null
- android - 在 Android Studio 中以编程方式将文本添加到 TextView
- veins - 如何在静脉 5.0 中获得车辆计数?
- bash - 为什么“at”命令不将数据发送到指定的输出文件?