2017-08-01 5 views
2

私はVueの中に単純なテーブルを持っている:Vueで特定のデータ値にスクロールする方法は?

<tbody> 
    <tr v-for="(item, index) in items"> 
     <td> 
      ... 
     </td>  
    </tr> 
</tbody> 

itemsは動的unshift経由で追加されています。

jQuery(document).keydown((e) => { 
    const which = e.which; 

    if ([38, 40].indexOf(which) != -1) { 
     e.preventDefault(); 

     if (this.active_index == null) { 
      this.active_index = 0; 
     } else { 
      if (e.which == 38) { 
       // up 
       this.active_index--; 
      } else { 
       // down 
       this.active_index++; 
      } 
     } 

     console.log(this.items[this.active_index]) 
    } 
}); 

それが何らかの形でthis.items[this.active_index]要素またはそれにスクロールするには、その位置を取得することが可能です:主なものは、私は、私はこのようにそれをやったdownキーので、upを経由して、テーブルをナビゲートする必要があるということです。

答えて

1
<tbody> 
    <tr v-for="(item, index) in items" ref="'dom'+index"> 
     <td> 
      ... 
     </td>  
    </tr> 

バインドrefdata、uはDOMを取得する必要がある場合、uはthis.$refs[dom${this.active_index}]

を使用することができます
関連する問題