初心者でFirebaseを使用してアプリ開発の勉強している者です。
調べても解決策が不明の為、質問させて頂きます。
ご回答よろしくお願い致します。
前提・実現したいこと
Cloud Firestoreに登録したプロフィールを、検索できる仕組みをつくっています。
ドキュメントIDで検索して、各フィールドのプロフィール情報を取得すると言うものです。
発生している問題・エラーメッセージ
Google Chromeのコンソール上では、エラーメッセージが出ません。
しかし、検索結果(list2)が表示されません。
該当のソースコード
javascript
1//変数 2var id_find = null; 3var id_msg = null; 4var id_list = null; 5 6function doLoad() { 7 id_find = document.querySelector('#find2'); 8 id_msg = document.querySelector('#msg2'); 9 id_list = document.querySelector('#list2'); 10} 11 12var db = firebase.firestore(); 13let coll = db.collection("profile"); 14 15//ID検索機能 16function idAction() { 17 coll.where('doc.value', '==', id_find.value) 18 .get() 19 .then((snapShot)=> { 20 let id_result = ''; 21 snapShot.forEach((doc)=>{ 22 let data = doc.data(); 23 id_result += '<li>' + data.name + ' [' + data.gender + ' :' + data.age + ']</li>' 24 }); 25 id_list.innerHTML = id_result; 26 id_msg.textContent = '検索結果: 【' + id_find.value + '】 のプロフィール'; 27 }) 28 .catch(function(error) { 29 console.error("Error document_id: ", error); 30 }); 31}
HTML
1<body onload="doLoad();"> 2 <table> 3 <tr> 4 <th>ID</th> 5 <td><input type="text" id="find2"></td> 6 <td><button onclick="idAction();">検索</button></td> 7 </tr> 8 </table> 9 <h2 id="msg2"></h2> 10 <hr> 11 <ol id="list2"></ol> 12</body>
試したこと
ドキュメントIDを単純な001などにしてみても取得出来なかったので、IDの入力間違いもないです。
function idAction(){ の下に (async () => { try { を入れてみたりもしましたが駄目でした。
あなたの回答
tips
プレビュー