Mobx 中将监听对象的observable 对象 改为正常的数据格式 用toJS 保留查询的搜索条件

  componentWillMount() {
    var newPaging = Object.assign({}, this.state.paging, store.paging);
    if (JSON.stringify(toJS(store.coursePrefSearchData)) !== '{}') {
      this.setState(
        {
          isInitValue: true,
          paging: newPaging,
          searchData: toJS(store.coursePrefSearchData),
        },
        () => {
          this.onSearch(this.state.searchData, this.state.paging);
          store.coursePrefSearchData = {};
        }
      );
    }
  }

  

  // 保留搜索条件(课程偏好)
  @observable coursePrefSearchData = {};
  @observable paging = {};
  @action saveSearchData = (data,paging) => {
    runInAction(() => {
      this.coursePrefSearchData = Object.assign({}, this.coursePrefSearchData, data);
      this.paging=Object.assign({},this.paging,paging)
    });
  };

  

上一篇:android – 当第一个Observable为空时RxJava concat


下一篇:观察者模式