第6章 クライアントアプリの変更
クライアントアプリを変更して、受け取ったサーバー応答から timestamp 属性を表示するようにします。
まず、応答のプレースホルダーを作成します。
- アプリ、クラウドアプリ & サービス ページに移動します。
- Cordova App クライアントアプリを開きます。
- エディター を開きます。
-
www/index.htmlファイルを開きます。 受信した
timestampを表示する<div>を新たに追加します。この要素は、受信した値のプレースホルダーとして機能します。
以下の行を見つけます。
<div id="cloudResponse" class="cloudResponse"></div>
これを以下のコードで置き換えます。
<div id="cloudResponse" class="cloudResponse"></div> <div id="timestamp" class="cloudResponse"></div>
- ファイル > 保存 を使用するか、Ctrl + S (Windows の場合) もしくは cmd + S (Mac の場合) のショートカットを使用して変更を保存します。
Say Hello From The Cloud ボタンのハンドラーを編集して、受信した timestamp の値をプレースホルダーに表示するようにします。
エディターで
www/js/hello.jsファイルを開きます。このファイルには、Say Hello From The Cloud ボタンのクリックハンドラーが含まれています。これは
$fh.cloudAPI を使用してクラウドアプリの/helloエンドポイントを呼び出し、プレースホルダー<div id="timestamp">要素を作成します。プレースホルダーに受信した
timestampの値を設定します。以下のコードを見つけます。
document.getElementById('cloudResponse').innerHTML = "<p>" + res.msg + "</p>";これを以下のコードで置き換えます。
document.getElementById('cloudResponse').innerHTML = "<p>" + res.msg + "</p>"; document.getElementById('timestamp').innerHTML = "<p>" + res.timestamp + "</p>";変更を保存します。
プレビューが自動的に更新されます。
Say Hello From The Cloud をプレビューでクリックします。
ボタンの下のエリアには、タイムスタンプを表す数字が表示されるようになります。これが表示されていない場合には、ページを更新します。

Where did the comment section go?
Red Hat's documentation publication system recently went through an upgrade to enable speedier, more mobile-friendly content. We decided to re-evaluate our commenting platform to ensure that it meets your expectations and serves as an optimal feedback mechanism. During this redesign, we invite your input on providing feedback on Red Hat documentation via the discussion platform.