Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/rust/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/powerbi/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Reactjs 通过API调用初始化存储_Reactjs_Reactjs Flux - Fatal编程技术网

Reactjs 通过API调用初始化存储

Reactjs 通过API调用初始化存储,reactjs,reactjs-flux,Reactjs,Reactjs Flux,我想用数据库中存储的数据初始化存储。然后我想从我的组件调用此存储来设置状态 class BucketlistStore extends EventEmitter { constructor(props){ super(props); request.get(url) .set('Accept', 'application/json') .end(function(err, response) {

我想用数据库中存储的数据初始化
存储
。然后我想从我的
组件
调用此存储来设置状态

class BucketlistStore extends EventEmitter {
    constructor(props){
        super(props);
        request.get(url)
            .set('Accept', 'application/json')
            .end(function(err, response) {
                if (err) return console.error(err);
                this.bucket_list = response.body;
            });

    }

    getAll(){
        return this.bucket_list;
    }
}
然后在我的组件中:我想做如下事情:

class BucketApp extends React.Component {
    constructor(props) {
        super(props);
        this.state = {
            bucket_list: BucketlistStore.getAll()
        };
    }
    //...render stuff

但是,我得到了这个错误
无法在此行设置未定义的属性'bucket\u list':
this.bucket\u list=response.body。关于如何解决这个问题,您有什么想法吗?

为了更好地理解这个问题,您能解释一下为什么决定
EventEmitter
?redux不是更适合吗?@yuantonito事实上,我对reactjs非常陌生,在阅读文档之后,我遇到了Flux和redux架构。我只是选择使用Flux,因为它现在看起来不那么复杂。为了更好地理解这个问题,你能解释一下为什么决定使用
EventEmitter
?redux不是更适合吗?@yuantonito事实上,我对reactjs非常陌生,在阅读文档之后,我遇到了Flux和redux架构。我只是选择使用Flux,因为它现在看起来不那么复杂。