小编Bha*_*n K的帖子

动态HTML字符串反应组件

我将从我的模板渲染中获取动态html内容,该内容由其他反应组件呈现.我如何将这个html字符串转换为React组件,以便我可以在我的渲染函数中使用该组件.请注意,我想保留用于差异的特定反应属性.

React.createClass( {
  var self = this;

  componentWillMountDown : function() {
    //htmlString is essentially huge dynamic one in my actual case
    var htmlString = "<div class='classDiv' react-id="0.1"><input type='text'/></div>";
    self.setState({responseString : htmlString});
    self.forceUpdate();
  },
    
  render: function() {
    var Response = this.state.responseString;
    //how would I return the react component as response?
    return (<Response/>); //does not work. err is it shd be valid react component
   }
});
Run Code Online (Sandbox Code Playgroud)

我已经尝试将htmlString转换为HTMLDocument对象,并在willmount回调中递归创建React.createElement并设置react组件.但是,错误是类型toUpperCase未定义.

javascript reactjs

12
推荐指数
2
解决办法
2万
查看次数

标签 统计

javascript ×1

reactjs ×1