我正在尝试使用下面的教程here将Firebase中的数据绑定到名为‘notes’(数组)的react状态
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');是否无法正常工作?
发布于 2015-12-03 17:22:18
firebase返回一个对象数组。当你这样做的时候
{this.props.notes.map(function(note,index){
return <li key={index}>{note}</li>
})}{注意}这是一个对象,我认为你需要再次循环对象键或在你的应用程序中使用https://www.npmjs.com/package/react-addons-create-fragment。
像这样的东西
var addons = require('react-addons-create-fragment');
return <li key={index}>{addons(note)}</li>发布于 2015-11-16 07:13:39
由于React的this.refs,this.ref有点令人困惑--而且,我不理解this.ref.child。根据文档,这应该是可行的:
var ref = new Firebase('https://myname-github-notetaker.firebaseio.com'); //may need .com/something here
this.bindAsArray(ref, 'notes');https://stackoverflow.com/questions/33726179
复制相似问题