采纳答案成功!
向帮助你的同学说点啥吧!感谢那些助人为乐的人
重构Item组件导致下拉刷新内容无法将最新数据展示到列表首页,而是加到List底部
修改 state 之前,把最新的数据,插入到数组的最前头,然后再重新生成一个新的 datasource 替换到 state 试试看,这个是数据顺序的问题
谢谢老师解答,不过,您讲的这种解决方案就是您代码里写的啊,我也都照着写的。这段代码在没有抽象Item组件的时候,确实可以刷新到最前面的数据,但是抽象后就跑后面了。不明白问题在哪里
另外为什么每次刷新都是10条数据,没有设置每页加载的数据项啊
从服务器端可以设置一下加载的
还有一个原因,我用的是 es6 的语法,除了在 componentDidMount 方法中初始化接受 row 参数外,每次下拉刷新,还需要在 componentWillReceiveProps 方法中接受 nextProps 参数。
componentWillMount() {
console.log(
'---- component will mount: '
)
this
.props.row)
.setState({
row:
.props.row,
up:
.props.row.voted
})
}
componentWillReceiveProps(nextProps) {
'---- component will receive props: '
console.log(nextProps.row)
row: nextProps.row,
up: nextProps.row.voted
已解决。在 rowHasChanged 方法中,少写了个 return。
constructor() {
super
();
let ds =
new
ListView.DataSource({ rowHasChanged: (r1, r2) => {
return
r1 !== r2 } });
.state = {
dataSource: ds.cloneWithRows([]),
onLoading:
false
,
onRefreshing:
碰到了同样的问题,一直没解决
constructor() { super(); let ds = new ListView.DataSource({ rowHasChanged: (r1, r2) => { return r1 !== r2 } }); this.state = { dataSource: ds.cloneWithRows([]), onLoading: false, onRefreshing: false, } }
if
(data.success) {
var
items = cachedData.items.slice()
(page !== 0) {
//拼接读取出来的数据到缓存对象里
items = items.concat(data.data)
cachedData.nextPage += 1
else
{
items = data.data.concat(items)
cachedData.items = items
cachedData.total = data.totalCount
setTimeout(
function
(){
(page!==0) {
that.setState({
//将拼接出来的数据重新加载进作品列表中
dataSource: that.state.dataSource.cloneWithRows(cachedData.items),
isLoading:
isRefreshing:
},1000)
莫非这个代码有 bug?我本地测试是好的,你先往后面看课程,跟完课程再回头看这个 state 数据次序的问题,看看我课程后面有没有再提到这里的代码改动
最后解决了没,我的也是这样,过一段时间自动好了,然后现在又不行了
登录后可查看更多问答,登录/注册
全面掌握React Native技术,不止步前端开发,让你移动领域大放光彩
3.2k 7
1.9k 7
1.1k 7
1.3k 7
964 6
购课补贴联系客服咨询优惠详情
慕课网APP您的移动学习伙伴
扫描二维码关注慕课网微信公众号