Reputation:
I want to render the table data like below.
However, the second line of "Available Channel" return value is number and I want to get the string. like 0--None, 1--Web, 2--Pos....
I try to use the paymentType function to switch it but it did not work. It seems that this function did not run at all. But I do not know why
<table>
...
<tr>
<td> { this.paymentType(id) } </td>
<tr>
</table>
And the function I wrote likes:
paymentType(id){
if(id===0) { return "None"}
else if(id===1) { return "Web"}
else if(id===2) { return "Pos"}
}
I only got a blank line.
I changed it to arrow function, still a blank line.
<table>
...
<tr>
<td> { () => this.paymentType(id) } </td>
<tr>
</table>
I bind this in the constructor method, still a blank line.
constructor(props){
super(props)
this.paymentType = this.paymentType.bind(this)
}
I wonder how to solve this problem and all your replies would be appreciated.
Upvotes: 0
Views: 47
Reputation: 2308
Just call your paymentType function directly, don't wrap it an an arrow function declaration:
{ this.paymentType(payment.payment_type_id) }
As you had it you efectively had a function declaration in the curly braces, you were not calling your helper function.
Upvotes: 2