はじめまして。閲覧ありがとうございます。
只今react nativeを勉強しております。
mapで配列を回した時、対応している画像を読み込みたいと考えております。
その際何故か変数を読み込むことが出来ません。お力をいただけるとありがたいです。
reactnative
1--諸々省略 2 3export default class App extends React.Component { 4 5 render() { 6 const sam = "a"; 7 const bottons = ["a","b","c","d"]; 8 return ( 9 <View> 10 {bottons.map( (botton,index) => { 11 return ( 12 <Image source={require(`./img/${botton}_botton.png`)} /> 13 ); 14 })} 15 </View> 16 ); 17 } 18}
このようにbottonsの中身を挿れて
a_botton.png
b_botton.png
c_botton.png
d_botton.png
という順番で画像を出しいのですがなぜかエラーが出てしまいます。
reactnative
1--諸々省略 2 3export default class App extends React.Component { 4 5 render() { 6 const sam = "a"; 7 const bottons = ["a","b","c","d"]; 8 return ( 9 <View> 10 {bottons.map( (botton,index) => { 11 return ( 12 <Image source={require(`./img/${sam}_botton.png`)} /> 13 ); 14 })} 15 </View> 16 ); 17 } 18}
これなら
a_botton.png
はきちんと表示されます。(b,c,d)も変更して試してみましたので、画像はあります。
<Text></Text>
の中に入れるときちんと表示されるのですが・・・
アドバイスいただけると幸いです。
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2019/07/03 05:21