Emberjs-temp-modify--actions-first-param

提供:Dev Guides
移動先:案内検索

テンプレート変更アクションの最初のパラメーター

_ \ {\ {action}} _ヘルパーの値オプションを指定することにより、アクションの最初のパラメーターを変更できます。

構文

<input type = "text" value = {{name}} onblur = {{action "action-name"}}/>

以下の例は、値オプション付きの_ \ {\ {action}} _ヘルパーを使用してアクションの最初のパラメーターを変更する方法を示しています。 新しいコンポーネントを作成し、次のコードで_post-action.js_という名前を付けます-

import Ember from 'ember';

export default Ember.Component.extend({
   actions: {
      actionFirstParameter(newName) {
         document.write('Name is:'+' '+newName);
      }
   }
});

次のコードで_app/templates/_の下に作成された_post-action.hbs_ファイルを開きます-

<label>Enter the name:</label>
<input type = "text" value = {{yourName}} onblur =
   {{action "actionFirstParameter" value = "target.value"}}/>
{{outlet}}

次に、次のコードで_app/templates/_の下に作成された_application.hbs_ファイルを開きます-

{{post-action}}
{{outlet}}

出力

エンバーサーバーを実行すると、値を入力するための入力ボックスが表示されます-

Ember.jsテンプレートアクションを最初に変更するパラメーター

以下のスクリーンショットに示すように、ユーザーが言及した入力フィールドの値が表示されます-

Ember.jsテンプレートアクションを最初に変更するパラメーター