我是新的Angular开发人员。我想知道是否有一种优雅的方法可以简化下面的重复代码。
addTransaccion() {
try {
if (this.idTransaccion === '0') {
this.transaccionesSrv.addTransaccion(data)
.then(res => {
if (res) {
this.router.navigate(['/cuentas/transacciones'], { queryParamsHandling: "preserve" });
}
});
} else {
this.transaccionesSrv.actualizarTransaccion(data, this.idTransaccion)
.then(res => {
if (res) {
this.router.navigate(['/cuentas/transacciones'], { queryParamsHandling: "preserve" });
}
});
}
} catch (error) {
this.envioFormularioOk = false;
}
}
答案 0 :(得分:0)
也许是这样
(this.idTransaccion === '0' ? this.transaccionesSrv.addTransaccion(data) :
this.transaccionesSrv.actualizarTransaccion(data, this.idTransaccion))
.then(res => {
if (res) {
this.router.navigate(['/cuentas/transacciones'], { queryParamsHandling: "preserve" });
}
});
但是我认为很难阅读
答案 1 :(得分:0)
Model.objects.values('get_type_display')