reactjs - Immutable.js 不呈现列表数据
问题描述
我的减速器看起来像这样:
import { fromJS } from 'immutable';
const GET_LIST = 'GET_LIST';
const initialState = fromJS({
list: [{
ID: 1
},
{
ID: 2
}]
});
function reducer(state = initialState, action) {
switch (action.type) {
case GET_LIST:
return state
.set('list', action.payload);
default:
return state;
}
}
export default reducer;
这就是我的组件的样子:
class App extends Component {
render () {
return (
<div className="container">
<table className="table table-striped">
<tbody >
{this.props.list.map(item => {
console.log('Item: ' + item.get('ID'))
return (
<div>{item.get('ID')}</div>
);
})}
</tbody>
</table>
</div>
);
}
}
const mapStateToProp = (state) => {
console.log('state list: '+ state.reducer.get('list') );
return {
list: state.reducer.get('list'),
}
}
问题是:我正在尝试遍历“this.props.list”,但它没有在我的 html 页面中呈现数据。但是当我尝试 console.log 列表时,它在浏览器控制台中显示数据,但数据不会在 html 页面中呈现。我想在页面中显示 initialState 数据。
请任何人对此有解决方案。我希望每个人都明白这个问题。
解决方案
推荐阅读
- vue.js - Vue中的进度条服务
- c# - 在用户 (ClaimsPrincipal) 中有两个声明身份,其中只有一个用于 [Authorize]
- javascript - 无法读取未定义的属性“setState” - 进度条
- c++ - ETW:调用 TdhGetEventInformation 时出现访问冲突错误
- ubuntu - 安装 NFS 服务器的问题:服务器端 MacOS、客户端 SAMA5D27 板
- r - 错误:EmailException (Java):将电子邮件发送到以下服务器失败:smtp.office365.com:587。R
- r - 如何在 R 数据框中满足条件后的第二天有条件地删除数据值?
- reactjs - Material-UI & React:使用 Fade 组件 onScroll
- c# - 计算列表中自己结构的重复项
- python - Python:将一维数组(具有等面积坐标系)转换为二维数组(具有地理坐标参考系)