Sayfa bileşenimin alt öğeleri olarak blok listelerini oluşturmaya çalışıyorum. Şimdiye kadar sadece görünen blokların konsolunu görüyorum. Konsolda veriler uygun olsa bile, bloklar hiç oluşturulmaz.React, çocukları oluşturmayacak, ancak konsol günlüklerini doğru şekilde yazdı
Yanlış
var Block = React.createClass({
render: function() {
var block = this.props.item;
return (
<div className="row" key={block.id}>
<p>{block.name}</p>
</div>
);
}
});
var Page = React.createClass({
getInitialState: function() {
return {
page: '',
blocks: [],
newBlockValue: ''
};
},
componentDidMount: function() {
this.serverRequest = $.get("/pages/"+this.props.page+".json", function (result) {
this.setState({
page: result.page,
blocks: result.blocks
});
}.bind(this));
},
componentWillUnmount: function() {
this.serverRequest.abort();
},
render: function() {
var page = this.state.page;
return (
<div className="row">
{this.state.blocks.forEach(function(block){
console.log(block);
<Block key={block.id} item={block} />
})}
<form id="add_new_block">
<input type="text" id="new_block" value={this.state.newBlockValue} onChange={this.handleChange} autoComplete="off"/>
<input type="submit" value='Save' onClick={this.createBlock}/>
</form>
</div>
);
}
hatalar:
Ayrıca aksi takdirde
undefined
bir dizi ile bitireceğiz, sizinBlock
elemanreturn
gerekir? – erichardson30Hiç de değil, sadece gibi nesneler: Object {id: 8, name: "foo"} –
Formunuz beliriyor mu? – erichardson30