添加注释jsx逻辑

时间:2016-12-07 10:39:31

标签: reactjs comments

有必要在方法clickSubmitComment()中,将写入逻辑添加到textarea的注释文本数组中,我还在学习告诉我如何或共享链接。

comment.jsx:

extension String {
    func index(of string: String, from startPos: Index? = nil, options: CompareOptions = .literal) -> Index? {
        let startPos = startPos ?? startIndex
        return range(of: string, options: options, range: startPos ..< endIndex)?.lowerBound
    }
}

和,commentForm.jsx:

import React from 'react';

export default class Comment extends React.Component {
    constructor(props){
        super(props);
    }
    render() {
        const comment = this.props.comment.map((commentForm, index) => {
        return <CommentForm key={index} {...commentForm}/>
        });
        return (
            <div className="media-body">{comment}<br></br></div>
        );
    }
}

2 个答案:

答案 0 :(得分:1)

将onChange添加到textarea并将其值保存到状态,然后onButton单击获取状态值。像这样:

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

      this.state = {
        comment: ""
      }
    }

    handleComment(e){
        this.setState({comment: e.target.value});
    }

    clickSubmitComment(){
        let comment = this.state.comment;
        //Do what you will with the comment
    }

        render(){
        return (
        <div>
            <div><textarea className="form-control" rows="3" onChange={this.handleComment.bind(this)}>{this.state.comment}</textarea><br></br>
            <button type="submit" className="btn btn-primary" onClick={this.clickSubmitComment.bind(this)}>Submit</button></div>
        </div>
      )
    }
}

React.render(<Test />, document.getElementById('container'));

Here is a fiddle.

答案 1 :(得分:1)

test -f !/usr/local/bin/myapp/*.sh || chmod 755 /usr/local/bin/myapp/*.sh