私はこの問題を何時間も悩まされています。私はFluxアーキテクチャを実装したいと思います。 ToDoリストを作成しようとしています。しかし、手元にある初期データをロードしたい。私todoStore.js例えば:反応フラックスAPI呼び出しによる初期データの読み込み
import toDoStore from './stores/todoStore'
class BucketApp extends React.Component {
constructor(props) {
super(props);
this.state = {
bucket_list: toDoStore.getAll()
};
}
そして、これが結構な作品:
import { EventEmitter } from "events";
class ToDoStore extends EventEmitter {
constructor(){
super();
this.bucket_list = [{
id: 123,
name: "Hi",
isCompleted: false
}]
}
getAll(){
return this.bucket_list;
}
}
私は私のtodo.js
で使用され、ここでいくつかの初期データを持っています。私はcomponent
からデータを受け取る基本的にcollection
の店を持っています。しかし、今私はデータベースからデータを初期化したい。だから、私はtodoStore.js
を更新しました:
class BucketlistStore extends EventEmitter {
constructor(){
super();
fetch(url)
.then(d => d.json())
.then(d => {
this.bucket_list = d;
});
}
getAll(){
return this.bucket_list;
}
}
をしかし、のgetAll()はundefined
を返します。これはなぜですか?私は間違って何をしていますか?