【发布时间】:2016-02-17 00:12:01
【问题描述】:
我正在尝试将我在 Firebase 中的数据绑定到名为“notes”(一个数组)的反应状态,下面的代码遵循教程 here:
var Profile = React.createClass({
mixins: [Router.State, ReactFireMixin],
getInitialState: function() {
return {
bio: [],
repos: [],
notes: []
}
},
componentDidMount: function() {
this.ref = new Firebase('https://myname-github-notetaker.firebaseio.com');
var childRef = this.ref.child(this.getParams().username);
this.bindAsArray(childRef, 'notes');
},
...
});
我在控制台中收到此错误:
Uncaught Error:
Invariant Violation: Objects are not valid as a React child (found: object with keys {.value, .key}).
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.
这是什么意思? this.bindAsArray(childRef, 'notes'); 行不正常吗?
【问题讨论】:
-
你确定错误在
bindAsArray()吗?因为该代码对我来说看起来是正确的。此外,这个错误很常见,通常意味着你试图在render()方法的虚拟 DOM 中包含一些错误
标签: javascript arrays object reactjs firebase