关于加载更多 list 的问题

来源:8-8 实现加载更多功能

weixin_慕神1362405

2020-12-31

immutable 好像对第二个 json 文件没起作用。点击更多内容后报错 item.get is not a function.

// actionCreators.js
import axios from ‘axios’;
import *as constants from ‘./constants’;
import { fromJS } from ‘immutable’;

const changeHomeData = (result) => ({
type: constants.CHANGE_HOME_DATA,
topicList: result.topicList,
articalList: result.articalList,
recommendList: result.recommendList
})

const addHomeList = (list) => ({
type: constants.ADD_HOME_DATA,
list: fromJS(list)
})

export const getHomeInfo = () => {
return (dispatch) => {
axios.get(’/api/home.json’).then((res) => {
const result = res.data.data;
dispatch(changeHomeData(result));
})
}
}

export const getMoreList = () => {
return (dispatch) => {
console.log(‘click’)
axios.get(’/api/homelist.json’).then((res) => {
const result = res.data.data;
// console.log(result);
dispatch(addHomeList(result));
})
}
}

-------------------------
// list.js
class List extends Component {
render() {
const { list, getMoreList } = this.props;
return (


{
list.map((item) => (
<ListItem key={item.get(‘id’)}>
<img
alt=""
className="pic"
src={item.get(‘imgUrl’)}
/>

{item.get(‘title’)}


{item.get(‘desc’)}




))
}
更多内容

)
}
}


// 报错提示
图片描述

写回答

1回答

Dell

2021-01-02

你在render里面,先打印一下list,看下结果

1
2
Dell
回复
weixin_慕神1362405
好的!
2021-01-03
共2条回复

React零基础入门到实战,完成企业级项目简书网站开发

主流新技术 React-redux,React-router4,贯穿基础语法

5275 学习 · 2496 问题

查看课程