错误尝试将样式数组设置为带有反应js

时间:2017-05-19 17:33:13

标签: javascript css reactjs

当尝试为元素指定样式时,我会重现下一个错误。

Error: Objects are not valid as a React child (found: object with keys {border, padding, whiteSpace, textOverflow, overflow, position, float, height, width}). If you meant to render a collection of children, use an array instead or wrap the object using createFragment(object) from the React add-ons. Check the render method of `Gridnamic`.

我尝试使用Object.assign,将数组设置为内联样式= {{width:“45px”}}并且无效。

我的数组样式是:

var styles = {
columns: {
    border: "1px solid #ddd",
    padding: "5px",
    whiteSpace: "nowrap",
    textOverflow: "ellipsis",
    overflow:"hidden",
    position: "relative",
    float: "left", 
    height: "45px", 
    width: "200px"
},
columnSelect: {
    border: "1px solid #ddd",
    padding: "5px",
    whiteSpace: "nowrap",
    textOverflow: "ellipsis",
    overflow:"hidden",
    position: "relative",
    float: "left", 
    height: "45px", 
    width: "50px"
}

};

我的渲染方法是:

    return  <div>
                <p>{this.state.selected.length} seleccionados</p>
                <div className="table-responsive">
                            <div style={styles.row}>
                                <div style={styles.rowContent}>
                                    <div style={styles.columnSelect}><input type="checkbox" onClick={this.selectElement.bind(this)} className="selectAll"/></div>
                                    {this.state.columns.map(column =>
                                        <div style={styles.columns} key={column.name}>{column.title}</div>
                                    )}
                                </div>
                            </div>
                            <div style={styles.row}>
                                <div style={styles.rowContent}>
                                    <div> style={styles.columnSelect}</div>
                                    {this.state.columns.map(column =>
                                        <div style={styles.columns} key={column.name}>
                                            <input placeholder="Buscar" className="form-control" ref={'filter-'+column.name} name={column.name} onChange={this.filter.bind(this)} />
                                        </div>
                                    )}
                                </div>
                            </div>
                    </div>
                <p>{this.state.rows.length} registros.</p>
            </div>;

感谢开发者。

1 个答案:

答案 0 :(得分:0)

  1. 冷藏

  2. 问题出在此处:<div> style={styles.columnSelect}</div>。可能意味着做<div style={styles.columnSelect}></div>