2017-04-10 17 views
-1

エラーは発生していませんが、関数がトリガされません。私のexec_request関数をswitch文の上または下に置くことを試みましたが、まだ運がありません。 es6 arrow関数はswitch文では機能しません

+0

再生できません。具体的な例を作成してください。 – str

+1

おそらく 'this.exec_request(url)'?あなたはこれを[tag:reactjs]とタグ付けしたので、 –

+0

@Danあなたはコメントも答えです。 – Ved

答えて

2

const list_type = '';//'temp'; 
 

 
const temp = "tmp"; 
 
const shop_id = "123"; 
 

 
const exec_request = (url) => { 
 
    alert(url) // not execute here? 
 
} 
 

 
switch(list_type) { 
 
    case 'temp': { 
 
     const url = `/shops/spaces/${temp}`; 
 
     exec_request(url) 
 
     break; 
 
    } 
 
    default: { 
 
     const url = `/shops/${shop_id}/spaces`; 
 
     exec_request(url) 
 
    } 
 
}

exec_request = (url) => { 
    alert('test') // not execute here? 
} 

switch(list_type) { 
    case 'temp': { 
     const url = `/shops/spaces/${temp}`; 
     exec_request(url) 
     break; 
    } 
    default: { 
     const url = `/shops/${shop_id}/spaces`; 
     exec_request(url) 
    } 
} 
はおそらく this.exec_request(url)を呼び出す必要があります。

これをとタグ付けしたので、exec_requestはグローバルな機能ではありません。

関連する問題