加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

angularjs – 我们如何在ng-grid中添加一行然后选择该行?

发布时间:2020-12-17 17:19:26 所属栏目:安全 来源:网络整理
导读:我的团队一直在尝试以下方面: $scope.addTest = function () { var TestRow = { "name": "xx","description": "xx","subjectId": 15 }; $scope.gridOptions.selectAll() var testRowLength = $scope.gridData.push(TestRow); $scope.gridOptions.selectItem
我的团队一直在尝试以下方面:

$scope.addTest = function () {
        var TestRow = {
            "name": "xx","description": "xx","subjectId": 15
        };
        $scope.gridOptions.selectAll()
        var testRowLength = $scope.gridData.push(TestRow);
        $scope.gridOptions.selectItem(testRowLength - 1,true);
    }

但是最后一个selectItem没有正确执行select.所以我们尝试了以下方法:

$scope.$apply(function () {
            $scope.gridData.push(TestRow);
            $scope.gridOptions.selectItem(testRowLength - 1,true);
        });

现在我们收到一条错误消息:

Error: $apply already in progress

这个问题是在ng-grid博客上发布的一个问题,但它刚刚发布,我们需要尽快帮助解决这个问题.我希望有人可以就我们的方式向我们提出建议

解决方法

您过早选择该行,请改用ngGridEventData事件.我将新行推送到网格的开头,因此滚动更容易:

$scope.add = function(){
    var emptyContact = Utilities.newContact();
    var e = $scope.$on('ngGridEventData',function() {
        $scope.contactsGridOptions.selectItem(0,true);
        window.scrollTo(0,0);
        e();
    });

    $scope.contacts.unshift(emptyContact);
};

有关滚动的更多信息:How do I scroll an ngGrid to show the current selection?

相关的ng-grid问题:https://github.com/angular-ui/ng-grid/issues/354

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读