1
<v-data-table
:headers="menuheaders"
//this menus from api response
    :items="menus"
        item-key="usersmenu_menuid"
        items-per-page="1000"
        hide-default-footer=""
        class="elevation-1"
        >
            <template v-slot:item.usersmenu_read="{ item }">
                <v-checkbox :class="`read${item.usersmenu_read}`" :value="item.usersmenu_read === 1 ? true : false "></v-checkbox>
            </template>
            <template v-slot:item.usersmenu_edit="{ item }">
                <v-checkbox :class="`edit${item.usersmenu_edit}`" :value="item.usersmenu_edit === 1 ? true : false "></v-checkbox>
            </template>
            <template v-slot:item.usersmenu_add="{ item }">
                <v-checkbox :class="`add${item.usersmenu_add}`" :value="item.usersmenu_add === 1 ? true : false "></v-checkbox>
            </template>
            <template v-slot:item.usersmenu_delete="{ item }">
                <v-checkbox :class="`delete${item.usersmenu_delete}`" :value="item.usersmenu_delete === 1 ? true : false "></v-checkbox>
            </template>
        </v-data-table>

Hi all, i have problem with this code, i want to getElementByClassName

let read =  document.getElementsByClassName('read${usersmenu_read}')

But i dont know what i must fill in the flag.

let read =  document.getElementsByClassName(In this flag, What should i fill ?)

Please give me some explanation. Thanks for you all

4
  • You mean in ${usersmenu_read}? Commented Feb 7, 2020 at 9:47
  • yeah, i want get element from v-checbox by class name, but i dont know how to get it with getElementByClassName( i dont know what should i fill in here) Commented Feb 7, 2020 at 9:53
  • :class="`read${item.usersmenu_read}`" this gives class="read_and_here_item." and if you want get it document.getElementsByClassName(`read${usersmenu_read}`) you can use this. But usersmenu_read variable must be the same on v-checkbox class binding name. Add more code to understand the existing logic. Commented Feb 7, 2020 at 9:56
  • can you share your whole page component please ? Commented Feb 7, 2020 at 9:58

1 Answer 1

1

Did you try to use $refs in VueJS instead of using getElementsByClassName. Follow this: https://v2.vuejs.org/v2/api/#ref

 <v-checkbox :class="`read${item.usersmenu_read}`" ref="readCheckbox" :value="item.usersmenu_read === 1 ? true : false "></v-checkbox>

// and use it in the component
this.$refs.readCheckbox

Update: for multiple checkbox
You can assign a ref to v-data-table instead directly in v-checkbox, and get all check box in DOM by use Vue $refs same above.
If you want to use getElementsByClass, you can give the checkboxes with a same name that not depend on menus data, say it's "menu-checkbox". Your checkbox will be:

<v-checkbox class="menu-checkbox" :class="`read${item.usersmenu_read}`" :value="item.usersmenu_read === 1 ? true : false "></v-checkbox>
// same for edit/add/delete

Now you can retrieve all checkboxes by:

document.getElementsByClassName('menu-checkbox')
Sign up to request clarification or add additional context in comments.

2 Comments

i have try it, and works but how to get multiples data (like fill in array or slice)?
@izzy45 I edited the answer for getting multiple checkboxes

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.