繁体   English   中英

未捕获的TypeError:无法读取未定义的属性“属性”

[英]Uncaught TypeError: Cannot read property 'attributes' of undefined

大家好,我试图在Web应用程序中执行删除操作,当我从数据库中删除一个元素时,在控制台中会显示此错误。请为此提供您宝贵的解决方案,谢谢。

Uncaught TypeError: Cannot read property 'attributes' of undefined
at _clearTreeSelection (orphanController.js:888)
at Scope.$scope.clearSelection (orphanController.js:659)
at HTMLDivElement.<anonymous> (orphanController.js:1058)

在第888行,这是我的代码:

//This is to clear the selectedNode of angular tree on modal close
_clearTreeSelection = function () {
$scope.orphanData.orphanText = 
$scope.orphanData.orphan.attributes.text;//This is line no.888
if ($scope.OntologyTree && $scope.OntologyTree.currentNode) {
        $scope.OntologyTree.currentNode = null;
    }
};

在第659行,这是我的代码:

$scope.clearSelection = function () {
    _clearTreeSelection();//line no.659
    _clearGazetteerSelection();
};

在第1058行,这是我的代码:

_modal.on('hidden.bs.modal', function () {
    $scope.suggestionListSearchText = '';
        $scope.clearSelection();// line no. 1058
    });
}

我已经检查了全部stackoverflow,找不到适合此问题的解决方案。

这意味着您的$scope.orphanData.orphanundefined 查找在哪里声明了该对象,并确保它引用了一个对象。

由于尝试访问对象上的属性但该对象不存在,因此出现此错误。 首先,应确保orphan属性实际上作为对象存在,以便可以访问其上的attributes属性。

您需要进行的更改:

$scope.orphanData.orphan = {'attributes': {}}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM