当实体发生变化时,我试图卸载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
尚未卸载。