我正在從事離子2項目。我可以返回設備/手機中的所有聯繫人。但是,由於一次請求,我使用了性能非常低的承諾代碼。現在,我希望將這個承諾代碼更改爲observable。請幫我解決這個問題。如何將承諾轉換爲可觀察的?
findContact(searchKey){
if(searchKey.target.value == "" || searchKey.target.value == undefined || searchKey.target.value == null){
this.contactSelected = false;
} else{
this.contactSelected = true;
}
let options = {
multiple: true,
hasPhoneNumber: true,
filter: searchKey.target.value
}
let cantactFields = ['displayName', 'phoneNumbers'];
Contacts.find(cantactFields, options).then(res => {
this.contactResults = res;
}, (er) => {
console.log(er);
})
}
Contacts.find()
是我使用承諾的方法。這種方法非常緩慢地返回聯繫人。
你可能具有XY問題,如果該方法是「慢」,沒有任何東西可觀察可以幫助。承諾和觀察者都能夠同時處理多個請求。而這個問題並沒有顯示相關的代碼。 – estus