【发布时间】:2018-10-24 01:24:35
【问题描述】:
我正在编写一个脚本,该脚本必须在位于 ./assets/ 的 .sql 文件中获取 SQL 查询,以便使用 Ionic 3 在我的本地数据库上执行这些查询。我想打开该文件,将每一行分别存储在一个数组中,然后使用自制的 executeSqlQuery() 函数在该数组上循环。
到目前为止,我认为由于 httpClient 模块,我已经能够打开文件,但没有更多...我一直在查看 File 模块(本机),但即使使用了也无法完成任何操作大量的文档和测试。
这是我所做的,我不知道如何从打开 './assets/queries.sql' 到 executeSqlQuery(queries[i]) :
querys.sql 摘录:
INSERT INTO `attaquesinf` VALUES ('bandaltchagui','circulaire','Bandal Tchagui','Bandal Chagi','Coup de pied circulaire niveau moyen.',NULL,NULL,NULL);
INSERT INTO `attaquesinf` VALUES ('dolyotchagui','circulaire','Dolyo Tchagui','Doleo Chagi','Coup de pied circulaire niveau haut.',NULL,NULL,NULL);
INSERT INTO `attaquesinf` VALUES ('biteurotchagui','crochet','Biteuro Tchagui','Biteureo Chagi','Coup de pied de l''intérieur vers l''extérieur dans un mouvement de torsion, avec le bol du pied.',NULL,NULL,NULL);
INSERT INTO `attaquesinf` VALUES ('nakkattchagui','crochet','Nakkat Tchagui','Nakka Chagi','Coup de pied crochet, frappe avec le talon.',NULL,NULL,NULL);
ExPage.ts 的摘录:
import { Observable } from 'rxjs/Observable';
import { HttpClient } from '@angular/common/http';
...
export class ExPage {
infsql: Observable<any>;
constructor(public httpClient: HttpClient) {
this.infsql = this.httpClient.get('./asset/queries.sql')
this.infsql
.subscribe(data => {
console.log('my data: ', data);
// ====> How can I use data ??
// ====> How can I loop through the content and executeSqlQuery(each line) ?
},
error => {
console.log("Error reading config file " + error.message + ", " + error.code);
});
}
};
...
提前感谢您的帮助!
【问题讨论】:
-
data()的值是多少?也许只是 data.split('\n') 就足够了,但我不知道 Ionic 的 HttpClient 是如何工作的。 -
如何探索数据中的内容?我试图在我的视图中将 {{ data }} 放在 之间,但我没有在屏幕上显示任何内容......我会在找到什么后立即尝试 data.split(\n)在里面以及如何使用它,谢谢! :)
-
就
console.log吧 -
在哪里可以阅读控制台日志?
标签: cordova ionic-framework ionic3 httpclient readfile