Bir api çağrısından dönen sonuçlarda 1 dizi öğesini geri almakta sorun yaşıyorum.ReactJS, Redux: STATE'deki bir dizi öğeyi nasıl iade ederim?
Bu, eylemlerdeki işlevdir.
followCheckList:function(userId){
for(var i= 0; i < userId.length;i++){
return{
types: [C.FOLLOW_CHECK_LIST, C.FOLLOW_CHECK_LIST_SUCCESS, C.FOLLOW_CHECK_LIST_FAIL],
promise: (client)=> client.get(`/graph/me/follows/${userId[i]}`)
.then(result => {
return result.id;
})
}
}
}
Benim düşürücüler
yüzden benim devlet benfollow_check_list : Array[2].
0: item1,
1: item2
görmelisiniz Ama bunun yerine görüyorum follow_check_list : action.result
2 sonuç bekliyorum
case C.FOLLOW_CHECK_LIST:
return{
...state,
follow_check_list:null,
error:false,
};
case C.FOLLOW_CHECK_LIST_SUCCESS:
return{
...state,
//break here
error:false,
follow_check_list: action.result
};
case C.FOLLOW_CHECK_LIST_FAIL:
return{
...state,
follow_check_list:false,
error:action.error,
};
default: return state || {loading: false,
loaded: null,
list_loaded: null};
}
:
follow_check_list : Array[1].
0: item1,
güncelleştirmesi Bileşenim. arrayIds 2 öğe var. peşin adamlar
let arrayIds=[];
const FollowStatus = React.createClass ({
componentWillMount(){
arrayIds.push(this.props.status);
},
componentDidMount(){
this.props.followCheckList(arrayIds)
},
Teşekkür
sizin followCheckList işlevi deyimi "dönüş" var gibi görünüyor
"followers_checklist" nereden geliyor? – markerikson
işlevinin içinde. Eğer tanımlanmamışsa, ben onu yaratırım. Fonksiyonun bir defadan fazla çağrıldığı zaman değişkenin ikinci kez başlatılmasını önlemek için bunu yaptım – joejoeso
Ve "sonuç" AJAX geri aramada neye benziyor? Tek bir nesne mi? Çünkü yaptığınız tek şey bu tek bir nesneyi diziye itmektir ... – markerikson