所以我已经成功地从一个数组
但我希望有一个按钮,每次单击它,就会呈现出另一个空组件来输入文本。在my array_node.jsx文件中直接添加一个button组件是否正确?到目前为止,我所做的是否正确?我还需要在
'values': ["hello", "world]
中呈现出组件,但我想添加一个按钮组件,以便每次单击它时,都会显示另一个空字段。它目前的样子是这样的:![Screenshot](https://istack.dev59.com/mcysg.webp)
var AddButton = React.createClass({})
中添加某种形式的newInput: function()
吗?谢谢!{...
childChange: function(name, valid, value) {
// update state
this.state.values = this.props.values;
// Using regex to find last digits from 0-9
var pattern = /[0-9]/;
var match = name.match(pattern);
// Parse char into int
var i = parseInt(match);
this.state.values[i] = value;
this.setState(this.state);
// Call parent callback
this.props.callback(
this.props.name,
this.props.node.valid(this.state.values),
this.state.values
);
},
addItem: function(values){
},
render: function() {
var that = this;
return (
<div id = "form">
{this.props.values.map(function(v, i) {
return (
<div>
{(that.props.node.get().constructor.name === "Parent") ?
<ParentComponent
name={that.props.name + i}
key={i}
timer={that.props.timer}
callback={that.childChange}
values={v}
newParent={that.props.node.get()}
/>
:
<NodeComponent
name={that.props.name + i}
key={i}
timer={that.props.timer}
callback={that.childChange}
value={v}
newNode={that.props.node.get()}
/>
}
</div>
)
})}
</div>
)
}
});
return ArrayNodeComponent
var AddButton = React.createClass({
addItem: function() {
},
render: function() {
return(
<div id="create_new_entry">
</div>
)
}
})
格式化:
var props = {
'name' : 'form',
'timer' : 1500,
'callback' : function(id, validity, value) {console.log(id, validity, value);},
'values': ["hello", "world"],
'node' : new FormatOC.ArrayNode({"__array__":"unique", "__type__":"string","__minimum__":1,"__maximum__":200,"__component__":"Input"},
)
}
React.render(React.createElement(ArrayNodeComponent, props), document.getElementById('react-component'));
React.createClass
而不是es6类有原因吗?如果你正在学习react,我强烈建议使用es6语法。除了一些奇怪的项目要求外,我几乎没见过任何人编写这样的react代码已经很久了。 - trixn