2015-11-08 42 views
0

我有迴流動作的一些動作,這是我的行動迴流listenAndPromise做動作多次

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'} 
    }; 
    },.. 

商店可以聽取動作如此之好,並可以返回我的反應組件。但是當我檢查網絡檢查時,我得到了許多時間的行動請求,我不知道發生了什麼事情?

request many times

+0

唐'不知道這是你問題原因的一部分,但是你在'.end(this.competed)'中有一個錯字。「它應該是'.end(this.completed);' –

回答

0

玉傢伙我解決了這個問題,讓我們去getInitData功能

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

我添加參數上getInitData功能,所以我console.log()秒paramater後,我得到的數據