17

eachで入力値をどのように使用できますeventsか? 私の以下のコードがあなたをよく説明してくれることを願っています。

HTML:

<template name="UpdateAge">
    {{#each Name}}
    <div data-action="showPrompt">
       <div>
          Some content
       </div>

       <div>
         <div>
            Some content
         </div>
       </div>
       <div>
           Name : {{name}}
           Age : <input type="text" name="age" value="{{age}}"/> //I need to access age values in event
       </div>
    </div>
{{/each}}
<template>

JS:

Template.UpdateAge.events({
  'click [data-action="showPrompt"]': function (event, template) {
        console.log(event.target.age.value); // TypeError: event.target.age.value is undefined
  }
});

私のアプローチがパラメーター値を渡すのに適しているかどうかわからないeventsので、提案を歓迎します。

4

2 に答える 2

1

イベントがコンテナ div にバインドされている場合、入力はターゲットから検索する必要がありevent.targetます。これは、イベントがアタッチされた要素が得られるためです。

内の任意の値にdivアクセスするには、まずその要素にアクセスしてから、その要素のプロパティを使用して必要なものにアクセスする必要があります.value。この場合は。

于 2015-05-20T07:38:07.637 に答える