1

Just new to use Vue.js and I have a question:

I have a array to build a table. If I double click the table row, the program will call a javascript function to get the selected item by its index.

<div id="vm-table">
    <table>
        <tr v-for="(item, index) in items" ondblclick="getItem('{{ index }}')">
            <td>{{ index }}</td>
            <td>{{ item.pk }}</td>
            <td>{{ item.description }}</td>
        </tr>
    </table>
</div>
<script>
    var vm = new Vue({
        el: "#vm-table",
        data: {
            items: []
        }
    });
</script>

I assume the array "items" already contains a list of items. In the above "tr" line it seems cannot get the "index" value and the value must be used in the inner "td" elements. If I need to get the parameter of index how can I do?

Thanks,

2
  • 1
    instead of ondblclick="getItem('{{ index }}')" try @dblclick="getItem(index)" Commented Sep 20, 2019 at 2:57
  • Successed! Thank you!! Commented Sep 20, 2019 at 3:00

1 Answer 1

1

Try this instead :

    <tr v-for="(item, index) in items" @dblclick="getItem(index)">
        <td>{{ index }}</td>
        <td>{{ item.pk }}</td>
        <td>{{ item.description }}</td>
    </tr>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.