简体   繁体   中英

How to pass an array to js button click in phalcon volt template engine

I am passing an associative array from my controller to my view and then iterating it on the template engine

 <tbody class="text-center">
                        {% for inv in inv_list %}
                            <tr>
                                <td><input type="checkbox" id="vehicle1" name="vehicle1" value="{{ inv['supplier_invoice_number'] }}"></td>
                                <td>{{ inv['contract_id'] }}</td>
                                <td>{{ inv['supplier_invoice_number'] }}</td>
                                <td>{{ inv['final_payable_amount'] }}</td>
                                <td>{{ inv['markup_value'] }}</td>
                                <td>{{ inv['markup_type'] }}</td>
                                <td>{{ inv['buyer_price'] }}</td>
                                <td><button class="btn btn-success" onclick="generateInvoice('{{ inv }}')">Invoice</button></td>
                                
                                <td><button class="btn btn-success">Invoice Email</button></td>

                            </tr>
                        {% endfor %}
                    </tbody>

Like above.I want to pass the value of the object in the onclick method,but its giving an error

Array to string conversion

.How to solve this.Please help me out

This Error Array to string conversion means tat you try to print an array. In your case inv is an array. I think that you need only to pass the id like onclick="generateInvoice('{{ inv['contract_id'] }}')" or a other unique value from your inc array.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM