无法卸载React组件

时间:2019-01-23 06:32:06

标签: angularjs reactjs

当实体发生变化时,我试图卸载react组件,因为我在我的angularJS项目中使用了rerenderSearchPanel函数,然后尝试使用initializeSearchPanel函数进行了安装。

rerenderSearchPanel内部,我有以下代码

searchElement && ReactDOM.unmountComponentAtNode(searchElement);

但是执行完这一行后,组件仍然存在其结构。

function rerenderSearchPanel(selectedEntity, savedChips) {
        var searchElement = document.getElementById("searchPanel");
        searchElement && ReactDOM.unmountComponentAtNode(searchElement);
        $scope.initializeSearchPanel(selectedEntity, savedChips);
    }

$scope.initializeSearchPanel = function (selectedEntity, savedChips) {

        var searchElement = document.getElementById("searchPanel");
        var searchDataSource = {
            method: "GET",
            catalogAPI: $scope.metaRestUrl + "specifications? 
                   q=specName;EQUALS;EntityAttribute&q=subType;EQUALS;English",
            searchAPI: $rootScope.smRestUrl + "graphSearch?limit=100&page=1",
            selectedEntity: (selectedEntity ? selectedEntity : 
                             $scope.currentEntity),
        };

        requestConfig.headers['TransformationEnabled'] = true;
        searchDataSource.headers = requestConfig.headers

        var options = {
            searchProps: {
                id: "searchInput1",
                placeHolder: "Search",
                editable: true,
            },
            chips: savedChips,
            onTokenChange: $scope.search,
            dataSource: searchDataSource
        }

        var search = React.createElement(SearchComponent, options);
        searchElement && ReactDOM.render(search, searchElement);
    }

但是ReactDOM.unmountComponentAtNode尚未卸载。

0 个答案:

没有答案