我有以下代码:
reduce.js:
import { fromJS } from 'immutable';
const initialState = fromJS({
"ff0bce4-ef2e-4eb6-b7b4-2f759d6ee0bb": {
"id": "8ff0bce4-ef2e-4eb6-b7b4-2f759d6ee0bb",
"type": "course",
"attributes": {
"title": "Wordpress"
},
"links": {
"self": "http://api.dev.course.com/api/v1/course/8ff0bce4-ef2e-4eb6-b7b4-2f759d6ee0bb"
},
"relationships": {
"modules": {
"links": {
"self": "http://api.dev.course.com/api/v1/course/8ff0bce4-ef2e-4eb6-b7b4-2f759d6ee0bb/relationships/modules",
"related": "http://api.dev.course.com/api/v1/course/8ff0bce4-ef2e-4eb6-b7b4-2f759d6ee0bb/modules"
}
}
}
},
"cd65128e-c89e-4a1a-8022-148e6bc673d2": {
"id": "cd65128e-c89e-4a1a-8022-148e6bc673d2",
"type": "course",
"attributes": {
"title": "Symfony"
},
"links": {
"self": "http://api.dev.course.com/api/v1/course/cd65128e-c89e-4a1a-8022-148e6bc673d2"
},
"relationships": {
"modules": {
"links": {
"self": "http://api.dev.course.com/api/v1/course/cd65128e-c89e-4a1a-8022-148e6bc673d2/relationships/modules",
"related": "http://api.dev.course.com/api/v1/course/cd65128e-c89e-4a1a-8022-148e6bc673d2/modules"
}
}
}
}
});
function list(state = initialState, action) {
switch (action.type) {
default:
return state;
}
};
export default list;
courseList.js
import React, { Component } from "react";
import { connect } from "react-redux";
class CourseListContainer extends Component {
render() {
return (
<div>
{
this.props.courses.map((course, s) => {
<div>test1</div>
})
}
</div>
)
}
}
function mapStateToProps(state, props) {
const common = state.get('common');
return {
courses: common.get('courseList'),
}
}
export default connect(mapStateToProps)(CourseListContainer);
当我尝试迭代课程时,收到以下警告: 警告:不支持将Maps用作子级,并且可能会产生意想不到的结果。将其转换为序列/可迭代的o ...
因此,我尝试使用不同的方法进行迭代,例如:valueSeq(),entrySeq ...,但是它们都不起作用。在这种情况下,我没有得到任何警告,但是没有两次看到“ asdasdasd”。在这种情况下,这就像课程是空的,但不是因为我检查了控制台,我才能看到相关信息。
答案 0 :(得分:1)
Immutable.Map#map
返回一个Immutable.Map
,因此您要给孩子一个Map。您应该可以做到:
或者
或者,您也可以使用按键:
Object.keys(courses).map()