如何从Firebase获取数据并将其放入this.props - React
How do I get data from Firebase and put it in this.props - React
所以,我有一个Firebase设置,我正在尝试将数据从snapshot.val((获取到this.props.device中,但是"this"在this.firebaseRef.on((函数中是"null"。有什么想法吗?
var RegisteredDevice = React.createClass({
mixins: [ReactFireMixin],
componentWillMount: function() {
this.firebaseRef = new Firebase("https://omniwolfdsn.firebaseio.com/Devices");
this.firebaseRef.on('value', function(snapshot) {
this.props.device = snapshot.val();
});
},
propTypes: {
name: React.PropTypes.string.isRequired,
device: React.PropTypes.string,
fire: React.PropTypes.string,
noise: React.PropTypes.string,
motion: React.PropTypes.string,
}
)};
您可以将this
作为第 4 个参数传递
this.firebaseRef.on('value', function(snapshot) {
this.props.device = snapshot.val();
}, (error) => console.log( error ), this);
根据文档,一次的签名是
on(eventType, successCallback, [failureCallback], [context] )
所以第四个参数可以this
相关文章:
- nextProps 总是与 this.props 相同,即使 props 在 componentWillReceiveP
- This.props.dispatch not a function - React-Redux
- TypeError:undefined不是对象(正在评估'this.props')-React Nati
- JavaScript: var {left, ...props} = this.props;
- this.props.history已被弃用(react router)
- ReactJS - {this.props.children} 是未定义的
- 如何从Firebase获取数据并将其放入this.props - React
- ReactJS:this.props.data.map 不是一个函数
- 当 props 扩展时,reactjs 的 this.props 会发生变化
- 反应:如何访问this.props.children中的参考文献
- 为什么在react native中使用this.props.navigator.replace再次渲染同一场景
- 未捕获类型错误:this.props.data.map不是函数(使用超级代理)
- '&&'操作符用{this.props.children &&React.cloneElement (t
- this.props 属性的问题,即使它们存在
- 断言在' this.props.children '中只传递了一个子节点
- React Redux Reducer: 'this.props.tasks.Map不是函数'错误
- React.js对this.props.children的设计实践
- 获取TypeError: this.props在ReactJs上没有定义
- this.props.enableEdit不是执行函数时的函数错误
- 有了reactjs和react-router,我可以显示一个组件或者{this.props.children}吗?