このアプリは問い合わせとして TABLE で 一覧を作成しますが、API を使用すると容易に更新も実行する事が可能です参考にするべきドキュメント ウェブ上でデータリストを操作する Firebase を JavaScript プロジェクトに追加する
<!DOCTYPE html>
<html>
<head>
<meta content="width=device-width initial-scale=1.0 minimum-scale=1.0 maximum-scale=1.0 user-scalable=no" name="viewport">
<meta charset="utf-8">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.3.1/css/bootstrap.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery.qrcode/1.0/jquery.qrcode.min.js"></script>
<link rel="stylesheet" href="https://lightbox.sakura.ne.jp/demo/two-section.css">
<script src="https://lightbox.sakura.ne.jp/demo/number-format.js"></script>
<script>
$(function(){
// **************************************
// ボタン
// **************************************
$("#load_json").on( "click", function(){
// データベース参照
var myFirebaseRef;
myFirebaseRef = firebase.database().ref('syain');
myFirebaseRef.once('value',
function(snapshot) {
if ( !snapshot.exists() ) {
alert( "データが存在しません" );
return;
}
loadData( snapshot );
},
function(error){
console.dir(error);
}
);
});
// **************************************
// このページ自身の QRコードの表示
// **************************************
$('#qrcode')
.css({ "margin" : "20px 20px 20px 20px" })
.qrcode({width: 160,height: 160,text: location.href });
});
// **************************************
// firebase => table
// **************************************
function loadData( snapshot ) {
$("#tbl").html("");
// データ用
var row_data;
var index = 0;
snapshot.forEach(function(data){
var obj = data.val();
// 初回はタイトル作成
if ( index == 0 ) {
// テーブルに行を追加
row_data = $("<tr></tr>").appendTo( "#tbl" );
$("<th></th>").appendTo( row_data ).text( "社員コード" );
$("<th></th>").appendTo( row_data ).text( "氏名" );
$("<th></th>").appendTo( row_data ).text( "フリガナ" );
$("<th></th>").appendTo( row_data ).text( "給与" );
$("<th></th>").appendTo( row_data ).text( "性別" );
$("<th></th>").appendTo( row_data ).text( "管理者" );
$("<th></th>").appendTo( row_data ).text( "生年月日" );
}
var re = new RegExp($("#sname").val());
if ( obj.name.search(re) != -1 ) {
// テーブルに行を追加
row_data = $("<tr></tr>").appendTo( "#tbl" );
$("<td></td>").appendTo( row_data ).text( obj.code );
$("<td></td>").appendTo( row_data ).text( obj.name );
$("<td></td>").appendTo( row_data ).text( obj.furi );
$("<td></td>").appendTo( row_data ).text( obj.kyuyo );
$("<td></td>").appendTo( row_data ).text( (obj.sex == 0 ? "男性" : "女性" ) );
$("<td></td>").appendTo( row_data ).text( obj.kanri );
$("<td></td>").appendTo( row_data ).text( obj.birthday );
}
index++;
});
}
</script>
</head>
<body>
<div id="head">
<input type="text" id="sname" name="sname">
<input type="button" id="load_json" value="検索">
</div>
<div id="extend">
<table class="table">
<tbody id="tbl">
</tbody>
</table>
<div id="qrcode"></div>
</div>
<!-- https://firebase.google.com/docs/web/setup?authuser=0#add-sdks_CDN -->
<!-- The core Firebase JS SDK is always required and must be listed first -->
<script src="https://www.gstatic.com/firebasejs/6.4.0/firebase-app.js"></script>
<script src="https://www.gstatic.com/firebasejs/6.4.0/firebase-database.js"></script>
<!-- TODO: Add SDKs for Firebase products that you want to use
https://firebase.google.com/docs/web/setup#config-web-app -->
<script>
// Your web app's Firebase configuration
var firebaseConfig = {
// *****************************************
// Firebase より取得した WEB 用 API情報
// *****************************************
};
// Initialize Firebase
firebase.initializeApp(firebaseConfig);
</script>
</body>
</html>
強調部分が Firebase より取得する部分ですが、firebase-database.js の行は追加になります
|
|
【JavaScriptの最新記事】
- Firebase の Realtime Database の JSON を jQuery の $.ajax で読み込んで TABLE を作成する
- IE や Firefox の開発者ツールのコンソールで簡単に localStorage を見る為の1行コード
- テキストエリアでタブ処理
- ブラウザ判定 : String.prototype.browser に登録して、文字列と実際のブラウザが一致したら true を返す
- jQuery UI の datepicker を使用した現在の日付文字列の取得 と 一般的な現在の日付文字列の加工取得処理
- geolocation を使用して『都道府県選択コンボボックス』の初期値を現在の緯度・経度から選択する
- 雪を降らす snowstorm.js の 特定 DIV 内での実装
- JavaScript : ブックマークレットの作り方
- いまさらですが、JavaScript で、グローバル領域を汚さない変数宣言の使用方法
- 二回目のロードは無視する、JavaScrip ライブラリの基本スケルトン
- ブックマークレットから、ページ中央に固定する IFRAME ウインドウを作成する
- JavaScript の全ての オブジェクトに同じ機能を持たせる
- JavaScript : コンボボックスの OPTION 部分の操作でたいていのテクニック
- JavaScript : 文字列で表現された日付を論理チェック
- HighslideJS 用貼り付けコード作成
- テキストエリアに入れた JSON データをチェックするコード(F12等の開発者ツールも使う) / JSON.stringify と JSON.parse
- エレメント(主にPRE)を選択状態にする
- JS : function() {} という『無名の処理』の理解
- GoogleVisualizationAPIを使用したブラウザ比率の円グラフ(2009年3月〜) / IE がまだ半分を占めてます
- Safari for windows の alert







参考にするべきドキュメント





















