android - 在 IONIC 中遇到未处理的 Promise Rejection 问题
问题描述
测试:我实际上正在使用我的手机,使用 ionic cordova run android -l 并使用 chrome://inspect im 调试应用程序。
当我访问 datosparte 页面时,它会在控制台中打印:
zone.js:1102
Unhandled Promise rejection:
{rows: {…}, rowsAffected: 1, insertId: 6736}
insertId: 6736rows: {length: 0, item: ƒ}
rowsAffected: 1[[Prototype]]: Object ;
Zone: <root> ; Task: null ;
Value: {rows: {…}, rowsAffected: 1, insertId: 6736}
undefined
这是我用来访问该页面的代码:
leerParte(parte){
this.datos.removeTpmParte();
this.datos.addTmpParte(parte.id);
this.navCtrl.navigateForward('datosparte');
}
removeTpmParte() 会:
removeTpmParte(){
this.database.executeSql("DELETE FROM tmpparte");
}
addTmpParte(id) 会:
addTmpParte(id) {
let data = [id];
return this.database.executeSql('INSERT OR REPLACE INTO tmpparte (id) VALUES (?)', data).then(data => {
});
}
最后,页面 datosparte 会:
import { Component, OnInit } from '@angular/core';
import { alert } from '../services/alert';
import { api } from '../services/api';
import { datos } from '../services/datos';
@Component({
selector: 'app-datosparte',
templateUrl: './datosparte.page.html',
styleUrls: ['./datosparte.page.scss'],
providers: [datos, api, alert]
})
export class DatospartePage implements OnInit {
constructor(private datos:datos, private api: api, private alert: alert) { }
idParte:any
url:string
json:any
datosParte:any
fotosParte:any
histoParte:any
ngOnInit() {
this.url = "https://NotARealURL.com/?f=partes.get&id="
this.datos.getDatabaseState().subscribe(rdy => {
if (rdy) {
this.datos.getTmpPartes().subscribe(idParte => {
this.idParte = idParte[0];
this.getDatos(this.idParte);
})
}
});
}
async getDatos(idParte){
if(typeof idParte === "undefined")return
let getDatosParte = this.url+idParte.id
console.log(getDatosParte)
this.api.getUrl(getDatosParte)
this.json = await this.api.getUrl(getDatosParte);
this.datosParte=[];
if(this.json.error['id'] != 0){
this.alert.showAlert("Error.", this.json.error['msg']);
return;
}
this.datosParte = this.json.parte.datos;
this.fotosParte = this.json.parte.fotos;
this.histoParte = this.json.parte.historico;
// console.log(this.datosParte);
// console.log(this.fotosParte);
// console.log(this.histoParte);
}
}
解决方案
推荐阅读
- javascript - 我在 JavaScript 中应用 .map 函数时引用的原始对象
- python - Numpy:将方阵的索引转换为其上三角索引的有效方法
- android - OnTouchListerner 不应将滑动打开 DrawerLayout 解释为长按
- sql - Oracle 使用单个查询更新和更改两个表中的少量列记录
- mysql - 包含变量和 SELECT FROM 的 INSERT INTO 表名
- python - 如何以接近零的成本部署 jupyter notebook 应用程序
- javascript - 承诺:然后在解决之前
- ios - 即使在 info.plist 文件 swift iOS 中添加 NSMicrophoneUsageDescription 后,应用程序也会崩溃
- mysql - SQL 日期
- javascript - 如何在画布圆的小圆弧上添加渐变效果?