我一直在研究一些ReactJS代码,当按下按钮时会传递一个值。
代码大部分工作正常,只是在尝试从<li>
元素传递值时,它会传递[object Object]
。
var React = require("react");
var { Panel } = require("react-bootstrap");
var JobStore = require("../stores/JobStore");
export var Spiderslist = React.createClass({
getInitialState: function(){
return {value: ""};
},
render: function () {
var ulStyle = {
listStyleType: "none",
padding: "0px",
margin: "0px"
};
var noPadding = {paddingLeft: 0, paddingRight:0,marginLeft:0,marginRight: 0};
var splst = this.props.splst;
var Lst = <ul style={ulStyle}>
{splst.map(function(listValue , i){
return <li><button type="submit" style={{marginBottom:"1%"}}
ref="domainInput" name="domain" value={listValue} className="btn btn- success" key={i}>{listValue}</button></li>; # This is where the value returns Object inside value={listValue} but text renders fine.
})}
</ul>;
return (
<form method="post" className="container-fluid" style={noPadding} action= {this.props.runner} onSubmit={this.onSubmit}>
<div className="col-xs-10" style={noPadding} onClick={this.onClick}>
{{Lst}}
</div>
</form>
);
},
onClick: function (ev) {
this.setState({value: this.refs.domainInput.getDOMNode().value});
},
onSubmit: function (ev) {
ev.preventDefault();
JobStore.Actions.startCrawl(this.state.value);
this.setState({value: ""});
}
});
问题似乎在于我在按钮的value={listValue}
处设置按钮的值。我怎样才能获得字符串值?