Redux 无法读取属性';调度';未定义的具有反应高度图的

Redux 无法读取属性';调度';未定义的具有反应高度图的,redux,react-highcharts,Redux,React Highcharts,我尝试使用redux使我的系列数据具有click事件,但是,当我尝试在回调中分派函数时遇到了问题,我使用的是React Highcharts库,我也尝试在安装组件后访问图表,但我不确定如何做,因为没有这方面的示例 import React, { Component } from 'react' import ReactHighcharts from 'react-highcharts' import {connect} from 'react-redux' import autobind fro

我尝试使用redux使我的系列数据具有click事件,但是,当我尝试在回调中分派函数时遇到了问题,我使用的是React Highcharts库,我也尝试在安装组件后访问图表,但我不确定如何做,因为没有这方面的示例

import React, { Component } from 'react'
import ReactHighcharts from 'react-highcharts'
import {connect} from 'react-redux'
import autobind from 'react-autobind'
import '../style.scss'
import axios from 'axios';
import { handleKeywordTweets } from '../actions'
import { store } from '../../../app.jsx'
require('highcharts/modules/wordcloud.js')(ReactHighcharts.Highcharts)

class WordCloud extends Component {
    constructor(props) {
        super(props);
        autobind(this);
    }

    render() {
        const { keywords } = this.props
        console.log(keywords);
        let words = []
        keywords.map(data => {
            let obj = {}
            obj.name = data.word
            if(data.count < 100) {
                obj.weight = 5
            } else {
                obj.weight = 6
            }
            words.push(obj)
        })

        let config = {
                chart: {
                    type: 'column',
                    inverted: false,
                    height:400,
                    marginTop:75,
                    marginBottom: 20,
                    borderRadius: 8,
                    backgroundColor: "#2B2E4A",
                },
                tooltip: {
                    enabled: false
                },
                series: [{
                    type: 'wordcloud',
                    data: words,
                    name: 'Occurrences',

                }],
                title: {
                    text: 'SENTIMENTAL WORDCLOUD',
                    y: 40,
                    style: {
                        color: '#ADB0D0',
                        fontFamily: 'Montserrat'
                    }
                },
                plotOptions: {
                    series: {
                        cursor: 'pointer',
                        events: {
                            click: function(event) {
                                let keyword = event.point.name
                                axios.all([
                                    axios.get(`/api/v1/tweets/@36,-115,7z?${keyword}`),
                                    axios.get(`/api/v1/tweets/@36,-115,7z/sentiments?keyword=${keyword}`)

                                ])
                                .then(axios.spread((tweets, sentiments) => {
                                    console.log(tweets);
                                    this.props.dispatch(handleKeywordTweets())
                                    console.log(sentiments);
                                }))
                                .catch(function(error){
                                    console.log(error);
                                })
                            }
                        }
                    }
                }
        }
        return (
            <ReactHighcharts config = {config}
            style={{ "min-width": "310px", "max-width": "800px", margin:" 0 auto"}}
            ></ReactHighcharts>
        );
    }
}

const mapStateToProps = (state) => {
    const { keywords } = state.places
    return { keywords }
}

export default connect(mapStateToProps)(WordCloud)
import React,{Component}来自“React”
从“react highcharts”导入react highcharts
从“react redux”导入{connect}
从“反应自动绑定”导入自动绑定
导入“../style.scss”
从“axios”导入axios;
从“../actions”导入{handleKeywordTweets}
从“../../../app.jsx”导入{store}
require('highcharts/modules/wordcloud.js')(ReactHighcharts.highcharts)
类WordCloud扩展组件{
建造师(道具){
超级(道具);
自动绑定(本);
}
render(){
const{keywords}=this.props
console.log(关键字);
让单词=[]
关键字.map(数据=>{
设obj={}
obj.name=data.word
如果(数据计数<100){
物体重量=5
}否则{
物体重量=6
}
字推(obj)
})
让配置={
图表:{
键入:“列”,
倒:错,
身高:400,
玛金托普:75,
marginBottom:20,
边界半径:8,
背景色:“2B2E4A”,
},
工具提示:{
已启用:false
},
系列:[{
键入:“wordcloud”,
数据:文字,
名称:“事件”,
}],
标题:{
文字:“感伤的文字云”,
y:40,
风格:{
颜色:'#ADB0D0',
丰特家族:“蒙特塞拉特”
}
},
打印选项:{
系列:{
光标:“指针”,
活动:{
单击:功能(事件){
let关键字=event.point.name
axios.all([
get(`/api/v1/tweets/@36,-115,7z?${keyword}`),
get(`/api/v1/tweets/@36,-115,7z/感伤?关键字=${keyword}`)
])
.然后(axios.spread)((推特、情绪)=>{
console.log(tweets);
this.props.dispatch(handleKeywordTweets())
console.log(情绪);
}))
.catch(函数(错误){
console.log(错误);
})
}
}
}
}
}
返回(
);
}
}
常量mapStateToProps=(状态)=>{
const{keywords}=state.places
返回{关键字}
}
导出默认连接(MapStateTops)(WordCloud)

请注意,您正在使用非箭头标记函数作为单击处理程序:

click: function(event) {
    let keyword = event.point.name
        axios.all([
            axios.get(`/api/v1/tweets/@36,-115,7z?${keyword}`),
            axios.get(`/api/v1/tweets/@36,-115,7z/sentiments?keyword=${keyword}`)
        ]).then(axios.spread((tweets, sentiments) => {
            console.log(tweets);
            this.props.dispatch(handleKeywordTweets())
                console.log(sentiments);
            })).catch(function(error){
                console.log(error);
            })
        }
通过使用非箭头表示法,函数定义自己的“this”值。 但是,arrow函数没有自己的“this”值,而是使用封闭的执行上下文的值(在您的例子中,“this”指的是React类WordCloud)


长话短说,请尝试将处理程序转换为箭头表示法,并尝试始终使用箭头表示法,因为前面的表示法已经过时了:)

请注意,您正在使用非箭头表示法函数作为单击处理程序:

click: function(event) {
    let keyword = event.point.name
        axios.all([
            axios.get(`/api/v1/tweets/@36,-115,7z?${keyword}`),
            axios.get(`/api/v1/tweets/@36,-115,7z/sentiments?keyword=${keyword}`)
        ]).then(axios.spread((tweets, sentiments) => {
            console.log(tweets);
            this.props.dispatch(handleKeywordTweets())
                console.log(sentiments);
            })).catch(function(error){
                console.log(error);
            })
        }
通过使用非箭头表示法,函数定义自己的“this”值。 但是,arrow函数没有自己的“this”值,而是使用封闭的执行上下文的值(在您的例子中,“this”指的是React类WordCloud)


长话短说,尝试将处理程序转换为箭头表示法,并且尝试始终使用箭头表示法,因为前面的表示法已经过时了:)

是的,这就是问题所在。谢谢,谢谢,谢谢!!我标记为正确答案,但我没有投票权,对不起!另外,我仍然不明白为什么非箭头表示法,函数定义了自己的“this”值,这违反了“this”应该指向最近的对象的原则,对吗?箭头表示法函数将
this
视为所包含执行内容的
this
,但是非箭头符号函数总是有自己的
上下文。是的,这就是问题所在。谢谢,谢谢,谢谢!!我标记为正确答案,但我没有投票权,对不起!另外,我仍然不明白为什么非箭头表示法,函数定义了自己的“this”值,这违反了“this”应该指向最近的对象的原则,对吗?箭头表示法函数将
this
视为所包含执行内容的
this
,但是非箭头表示法函数总是有自己的
上下文。