ReactJs检查所有复选框

时间:2015-07-14 09:30:45

标签: javascript select reactjs

我在表头中有一个选择所有组件渲染,我希望它在选中时检查页面上的所有复选框,如果其中一个复选框未选中,我希望select all也取消选择:

var SelectAll = React.createClass({

handler: function(e) {

    e.target.value;
    e.preventDefault();

    channel.publish({
        channel: "contact",
        topic: "selectAll",
        data: {
            contacts: this.props.data
        }
    });
},

render: function() {

    console.log(this.props.data.children);

    var id = this.props.contacts;
    var isSelected = this.props.data.isSelected;

    return (
        <div className="contact-selector">
            <input type="checkbox" checked={isSelected}
                onChange={this.handler} />
        </div>
    );
},

});

我的复选框在每个表格行中呈现:

var ContactSelector = React.createClass({

getInitialState: function() {
    return {
        selectedContacts:[]
    };
},

handleChange: function(e) {
    var id = e.target.attributes['data-ref'].value;

    if (e.target.checked === true){
        contactChannel.publish({
                    channel: "contact",
                    topic: "selectedContact",
                    data: {
                        id: id
                    }});
    } else{
        contactChannel.publish({
            channel: "contact",
            topic: "deselectedContact",
            data: {
                id: id
            }});
    }
},

render: function() {

    var id = this.props.data.id;
    var isSelected = this.props.data.IsSelected;

    return (
        <div className="contact-selector">
            <input type="checkbox"
                checked={isSelected} data-ref={id}
                onClick={this.handleChange} />
        </div>
    );
}

});

任何人都可以告诉我如何设置支票全部吗?使用州或参​​考等

0 个答案:

没有答案