呼び出すとき
- bindを使う
onClick={this.handleClickDelete.bind(this, "渡したい値")}
1 |
<span class="p"><</span><span class="nt">button</span> <span class="na">onClick</span><span class="p">=</span><span class="si">{</span><span class="k">this</span><span class="p">.</span><span class="nx">handleClickDelete</span><span class="p">.</span><span class="nx">bind</span><span class="p">(</span><span class="k">this</span><span class="p">,</span> <span class="nx">pod</span><span class="p">.</span><span class="nx">SubDomainName</span><span class="p">)</span><span class="si">}</span><span class="p">></span>Delete<span class="p"></</span><span class="nt">button</span><span class="p">></span> |
onClickを受け取る側の関数
handleClickDelete(SubDomainName)
の形で受け取るconsole.log(SubDomainName)
のように使う
1 2 3 4 5 6 |
<span class="nx">handleClickDelete</span><span class="p">(</span><span class="nx">SubDomainName</span><span class="p">)</span> <span class="p">{</span> <span class="nx">console</span><span class="p">.</span><span class="nx">log</span><span class="p">(</span><span class="nx">SubDomainName</span><span class="p">)</span> <span class="kd">const</span> <span class="nx">json</span> <span class="o">=</span> <span class="p">{</span><span class="dl">"</span><span class="s2">Name</span><span class="dl">"</span><span class="p">:</span><span class="nx">SubDomainName</span><span class="p">};</span> <span class="kd">const</span> <span class="nx">convert_json</span> <span class="o">=</span> <span class="nx">JSON</span><span class="p">.</span><span class="nx">stringify</span><span class="p">(</span><span class="nx">json</span><span class="p">);</span> <span class="kd">const</span> <span class="nx">obj</span> <span class="o">=</span> <span class="nx">JSON</span><span class="p">.</span><span class="nx">parse</span><span class="p">(</span><span class="nx">convert_json</span><span class="p">);</span> <span class="nx">console</span><span class="p">.</span><span class="nx">log</span><span class="p">(</span><span class="nx">obj</span><span class="p">)</span> |