2016-06-29 5 views
1

私はReactjsを持つ最初のアプリケーションを構築しており、Flux Modelを実装するためにAltライブラリも使用しています。 私は動詞を持っていますが、修正しようとしましたが、うまくいきませんでした。ここでアクションReactJsを使用Alt

import alt from '../alt'; 
class AddUserActions { 
constructor() { 
this.generateActions(
    'addUserSuccess', 
    'addUserFail' 
);} 
    addUser(payload) 
    {  
     $.ajax({ 
     type:'POST', 
     url:'/api/user', 
     data:{username:payload.username, 
     password:payload.password, 
     fbId:payload.fbId   
     } 
    }) 
    .done((data) => { 
    this.actions.addUserSuccess(data.message); 
    }) 
    .fail((jqXhr) =>{ 
    this.actions.addUserFail(jqXhr.responseJSON.message); 
    }); 
    } 
} 
export default alt.createActions(AddUserActions); 

は、data.messageとのLocalServer応答が "成功" で、ステータスPloblemがthis.actions.addUserSuccess(data.message);で発生し200: はここに私のコードです。 エラー:Uncaught TypeError: Cannot read property 'addUserSuccess' of undefined 私はその理由を知らなかった。私を助けてください!

答えて

0

this.generateActionsは...あなたはalt.generateActions(...)

も使用する必要があります何もしていないが、それはこのように自分でaddUserSuccessとaddUserFailアクションを抽出するために傷つけることはありません:

import Api from '../services/QuestionApi'; 

class QuestionActions { 
    constructor() { 
     // put auto generate actions here 
    } 

    getQuestions() { 
     Api.getQuestions().then((result) => { 
      this.getQuestionsSuccess(result); 
     }); 
     return true; 
    } 

    getQuestionsSuccess(data) { 
     return data; 
    } 

    createQuestion(question,state) { 
     Api.createQuestion(question).then((result) => { 
      this.createQuestionSuccess(result); 
     }); 
     return true; 
    } 

    createQuestionSuccess(data) { 
     this.getQuestions(); 
     return data; 
    } 


} 
export default (alt.createActions(QuestionActions)); 

これにより、必要に応じてアクションの他の機能を実行することができます。

関連する問題