2016-10-07 69 views
0

所以我想基于一个键输入具有嵌套的滚动焦点。为此,我使用了ng-focus,但我似乎误解了它的目的。AngularJS - 专注于嵌套滚动中的对象

这个JSFiddle显示了我到目前为止所做的。无论何时发现匹配,我将ng-focus="x._focus"设置为true,并在控制台日志中显示发生了这种情况。但滚动并没有移动到input领域的焦点。那个怎么样?

回答

1

嘿,我真的不明白你想要什么,但检查这,让我知道,如果这是你想要jsFiddle

function MyCtrl($scope) 
{ 
    $scope.list = [] 

    for(var i = 0; i < 500; i++){ 
     $scope.list.push({ 
     number: i, 
     _focus: false 
     }) 
    } 

    $(document).keypress(function(e) 
    { 
     for(var i = 0; i < $scope.list.length; i++) 
     { 
      if($scope.list[i].number === e.keyCode) 
      { 
       $scope.list[i]._focus = true 
       console.info('found : ', $scope.list[i]) 
       $scope.$apply(); // Apply changes and change the false to true in dom 

       $('#nestedScroll').animate(
       { 
        scrollTop: $("#nestedScroll span[scrollTo='true']").offset().top 
       }, "slow"); 

       return 
      } else { 
       $scope.list[i]._focus = false 
      } 
     } 
    }); 
} 
+0

什么有点。我已经更新你的小提琴http://jsfiddle.net/wjtz8xhr/13/,以便它可以找到我们正在寻找的物品。一个奇怪的是,当你第一次使用它时,如果你输入的数字小于第一个数字,它就不能正确显示 –

+0

对不起,我不理解你,但是我给你作为例如完美的作品,你可以找到你正在寻找的物品 – Diptox