如果通过reactjs解析,点击不工作

时间:2017-02-13 08:22:21

标签: javascript reactjs

我编写了一段代码,需要首先截断文本然后再点击阅读更多全文显示。但单击时点击不起作用



<script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.1.0/react.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.1.0/react-dom.min.js"></script>
<div id="test">
</div>
&#13;
{{1}}
&#13;
&#13;
&#13;

1 个答案:

答案 0 :(得分:0)

&#13;
&#13;
    var _parseText=(text, flag)=> {
      console.log(flag)
      if (text.length > 200 && flag == true) {
        return text.substr(0, 200) + ' <a onClick={_parseText(text,false)}>Read More...</a>';
      } else {
        return text;
      }
    }

class DC extends React.Component {
    constructor(props) {
      super(props);
    }


    render() {
        return ( 
          <p dangerouslySetInnerHTML={{__html:_parseText('Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industrys standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book.It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged.It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.', true)}}></p>)
}
}
        
ReactDOM.render(<DC/>, document.getElementById('test'));
&#13;
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.1.0/react.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.1.0/react-dom.min.js"></script>
<div id="test">
</div>
&#13;
&#13;
&#13;

将该功能放在组件外部并在没有它的情况下调用它。