【发布时间】:2016-01-19 09:48:19
【问题描述】:
当我控制台记录它返回未定义的状态但在我的反应开发工具中我可以看到结果数组。 这是组件:
var Categorias = React.createClass({
getInitialState: function () {
return {
items: []
};
},
componentWillMount: function (){
var firebaseRef = new Firebase("https://rapifood.firebaseio.com/categorias");
firebaseRef.on("child_added", function(dataSnapshot) {
var items= [];
items.push(dataSnapshot.val());
this.setState({
items: items
});
}.bind(this));
},
componentDidMount: function () {
console.log(this.state.items);
},
我做错了什么?
【问题讨论】:
-
您可能想尝试将
console.log放入渲染函数中。不确定在componentDidMount被触发时数据是否已经存在