javascript - 选择内部ng表,当重新加载ng表中的数据时,页面返回顶部

标签 javascript angularjs

我们正在使用 ng 表在页面上呈现一些数据。在表格内,ng-repeater 从对象数组中逐行渲染值。其中一列是一个选择框,其值取自在 Controller 内声明和填充的数组。

这是数组的声明:

$scope.CharacteristicsToChange = [];

这是方法中某处的数组的总体:

if ($scope.ItemProfile.ProductionDateRegistration != 'No')
    $scope.CharacteristicsToChange.push({ Name: 'Production date' });

if ($scope.ItemProfile.BestBeforeDateRegistration != 'No')
    $scope.CharacteristicsToChange.push({ Name: 'Best before date' });

选择框是:

<select class="form-control" id="ddlCharacteristics" ng-options="characteristic.Name as characteristic.Name for characteristic in CharacteristicsToChange" name="Characteristic" ng-model="inventory.SelectedCharacteristic" required>
    <option value="" class="select-placeholder"> Select characteristic type</option>
</select>

我们的问题是,当重新加载 ng 表的数据(每 10 秒)并且页面滚动到底部时,页面会返回到顶部。

我认为问题在于我们为 select ( $scope.CharacteristicsToChange ) 获取值的数组,因为当我删除该数组的填充部分时,重新加载问题不再发生。

最佳答案

页面上是否有任何 ng-ifng-show 实例?如果没有看到更多代码,听起来您实际上可能在重新加载数据时删除/隐藏 DOM 上的元素,然后重新创建它(从而使其滚动回顶部)

关于javascript - 选择内部ng表,当重新加载ng表中的数据时,页面返回顶部,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51835125/

相关文章:

javascript - Web api 未从 angularjs 接收日期

javascript - AngularJS配合ng-map实现动态热图可视化

node.js - `yo angular` 给出错误 : npm ERR! 代码 ENOENT npm ERR! errno 34(是的,我已经清理了缓存并设置了 .npmignore)

Angularjs + grunt + Bower + Gitlab CI。测试设置

javascript 函数仅适用于第一个元素

javascript - 如何使用 jquery 在 TR 中的单击事件上自动求和 TD 值

javascript - Angularjs int 过滤器在智能表中没有正确排序

javascript - 使用jquery更新选择中的文本

javascript - 在javascript中用三元运算符连接字符串

javascript - ActionScript 3 中类似 JSObject 的东西?