Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/reactjs/23.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 你的承诺会多次付诸行动_Reactjs_Refluxjs - Fatal编程技术网

Reactjs 你的承诺会多次付诸行动

Reactjs 你的承诺会多次付诸行动,reactjs,refluxjs,Reactjs,Refluxjs,我有一些反流动作,这是我的动作 var BeritaActions = Reflux.createActions({ 'getListBerita': { children: [ 'actions', 'completed', 'failed' ] }, 'getBerita': { children: [ 'actions', 'completed', 'failed' ] }, }); BeritaActions.ge

我有一些反流动作,这是我的动作

var BeritaActions = Reflux.createActions({
  'getListBerita': {
    children: [
      'actions', 'completed', 'failed'
    ]
  },
  'getBerita': {
    children: [
      'actions', 'completed', 'failed'
    ]
  },
});

BeritaActions.getListBerita.listen(function(param)
{
  return BeritaUtil.listBerita(param)
    .on('error', this.failed)
    .end(this.completed);
});

BeritaActions.getBerita.listenAndPromise(function(id)
{
  return BeritaUtil.read(id)
    .on('error', this.failed)
    .end(this.completed);
});
这是我的商店,听我的行动

Reflux.createStore({
  onprogress: false,
  type: null,
  init()
  {
    this.listenTo(BeritaAct.getListBerita.completed, this.getInitData);
    this.listenTo(BeritaAct.getListBerita.failed, this.getInitErrorData);
  },
  setType(type)
  {
    return this.type = type;
  },
  getCurrentData()
  {
    return _data;
  },
  getInitData(field)
  {
    console.log(field)
    let data = JSON.parse(field.text);
    if(data.meta.code == 200)
    {
      if(typeof _data[this.type] == 'undefined')//first open
      {
        //console.log('first')
        _data[this.type] = data.data;
      }else//on load more = merging data
      {
        //console.log(_data[this.type])
        _data[this.type] = update(_data[this.type], {$merge: data.data}); 
      }

      this.trigger(_data);

    }else
    {
      Toas.error({title:data.meta.message, content:''});
    }
  },...
所以我在我的组件中执行操作

React.createClass({
  getInitialState()
  {
    if(Progress.isAjax())
    {
      Progress.onProgress(true);
      BeritaStore.setType('list');
      BeritaAct.getListBerita({});
    }else
    {
      //not ajax
    }
    return {
      showloader: {display: 'none'},
      shownext: {display: 'block'}
    };
  },..
store可以很好地侦听操作,并可以返回我的react组件。但当我检查网络检查时,我多次收到行动请求,我不知道发生了什么


好了,伙计们,我解决了这个问题,让我们转到getInitData函数

getInitData(bind, field)
{
    console.log(field)
}

我在getInitData函数中添加了参数,因此在i console.log second paramater之后,我获取了数据

不知道这是否是问题的原因之一,但您在“.endthis.competited;”中有一个输入错误。应该是“.endthis.completed;”