Reect Ajax render 传递数据到子Component 获取不到数据
2016-06-15 20:48
411 查看
ajax获取数据一般都写在 componentDidMount 中,而render的调用周期又是在componentDidMount 前面
这导致了ajax还没有进行的时候,render已经完成了,所以在render里面是获取不到ajax的数据的
然后想到了React在更新数据的时候会重新渲染
so 在state中添加了一个状态 loadingData
它看起来是这个样子的
在rander中看起来是这个样子的
在ajx中看起来是这个样子的
这导致了ajax还没有进行的时候,render已经完成了,所以在render里面是获取不到ajax的数据的
然后想到了React在更新数据的时候会重新渲染
so 在state中添加了一个状态 loadingData
它看起来是这个样子的
getInitialState: function() { return { loadingData: false } }
在rander中看起来是这个样子的
return ( { this.state.loadingData ? <Helo /> : "" } )
在ajx中看起来是这个样子的
componentDidMount: function() { this.serverRequest = $.get(this.props.source, function (result) { this.setState({ loadingData: true }); var lastGist = result[0]; //do something }.bind(this)); }, componentWillUnmount: function() { this.serverRequest.abort(); }
相关文章推荐
- C#获取程序运行时间
- 如何修改vim中tab键的距离
- 自行车码表
- 图片人脸检测 (I)【sample改版 人眼检测】
- 蒟蒻的读入优化模板
- C++的多态
- 图像的轮廓检测
- 图像处理和图像识别中常用的OpenCV函数
- Spring MVC的实现原理
- Linux下find命令详解
- 关于UIView位置信息的总结和CATransform3D初步认识
- android Fragment 源码分析
- LintCode(72)中序遍历和后序遍历树构造二叉树
- Java关键字final、static使用总结
- Lombok学习
- zencart 安装和配置修改笔记
- C#重写Equals()
- HDU 2952 Counting Sheep 深搜
- 指针
- ORA-01652 无法通过128 (在表空间 TEMP中)扩展temp段 剖析解决