[英]Angular RouteGuard "A function whose declared type is neither 'void' nor 'any' must return a value"
[英]DEXIE - A function whose decl ared type is neither 'void' nor 'any' must return a value
我正在嘗試實現一個檢查價格是否在范圍內的功能。
數據位於IndexedDB中,我正在使用Dexie進行處理。
在這一刻,我無法編譯我的解決方案
public checkPrizeChange(codCli: string, codList: string, codArt: string, price: number): Observable<any> {
this._WebDBService.Listino_Articoli.filter(function (i){
return (i.codLis == codList && i.codArt == codArt);
}).toArray().then(
data => {
if(data.length != 1)
{
return Observable.of(false)
}
else{
if(data[0].prezzoMin >= price && data[0].prezzoMax <= price)
return Observable.of(true)
else
return Observable.of(false)
}
}
);
}
我不知道使用dexie的正確方法是什么...
我只需要檢查DexieTable行中的某些字段,沒什么困難,然后返回一個Observable ...
感謝支持
在此行之前添加return
:
return this._WebDBService.Listino_Articoli.filter(function (i){
Dexie方法toArray()返回一個Promise。 您想返回一個Observable。
可能,您應該執行以下操作:
public checkPrizeChange(codCli: string, codList: string, codArt: string, price: number): Observable<boolean> {
return Observable.fromPromise(this._WebDBService.Listino_Articoli.filter(i => i.codLis == codList && i.codArt == codArt).toArray().then(
data => {
if(data.length != 1)
{
return false;
}
else{
if(data[0].prezzoMin >= price && data[0].prezzoMax <= price)
return true;
else
return false;
}
}
);
}
另外,似乎您可以利用復合索引 “ [codLis + codArt]”來加快查詢速度。 如果使用Dexie 2.0,則可以重寫查詢以利用索引:
this._WebDBService.Listino_Articoli.where({
codLis: codLis,
codArt: codArt
}).toArray()
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.