我想知道如何定義數據類型以及如何使用getObject()返回對象(記錄)。目前,我能夠在獲得它的函數之外使用結果(記錄)的唯一方法就是調用另一個函數的結果。這樣,數據類型不需要指定。但是,如果我想返回值,我需要定義數據類型,我找不到它是什麼。我嘗試「動態」,但似乎沒有工作。例如「:indexed_db getObject() - 如何返回結果
fDbSelectOneClient(String sKey, Function fSuccess, String sErmes) {
try {
idb.Transaction oDbTxn = ogDb1.transaction(sgTblClient, 'readwrite');
idb.ObjectStore oDbTable = oDbTxn.objectStore(sgTblClient);
idb.Request oDbReqGet = oDbTable.getObject(sKey);
oDbReqGet.onSuccess.listen((val){
if (oDbReqGet.result == null) {
window.alert("Record $sKey was not found - $sErmes");
} else {
///////return oDbReqGet.result; /// THIS IS WHAT i WANT TO DO
fSuccess(oDbReqGet.result); /// THIS IS WHAT i'm HAVING TO DO
}});
oDbReqGet.onError.first.then((e){window.alert(
"Error reading single Client. Key = $sKey. Error = ${e}");});
} catch (oError) {
window.alert("Error attempting to read record for Client $sKey.
Error = ${oError}");
}
}
fAfterAddOrUpdateClient(oDbRec) {
/// this is one of the functions used as "fSuccess above
感謝克里斯,我會盡快詳細檢查你的答案,這應該有助於我更好地理解事情。一旦我完成了,我會的給它打個勾。 –