Display multiple checkbox in table format using <v-for> and <v-checkbox> in Vuetify?

限于喜欢 提交于 2020-06-17 14:14:07

问题


I'm using the VuetifyJs for VueJS and I'm trying to display checkbox in table format from an array of objects. Desired Output shown below :

When 'All Users' is checked all the checkboxes should be checked.


I created a row layout and divided this row into two flex boxes so I have the structure of row with two columns. I loop using 'v-for' and for every row display the value of the current index and the next index. But the last entry is repeated the next time the loop is iterated. The closest I could reach is as shown below:


CodePen Url: https://codepen.io/dhnsh/pen/ZRMgoE

I also tried to use table instead of layout and flex but could not make it. In the codepen I use the function 'checkLength' to get the next index because incrementing the 'index' with pre-increment operator gives error(probably due to array goes out of bounds).


I am struggling with the below queries :

1) How can we display the desired output in Vuetify ?

2) Is there anyway to iterate 'v-for' with increment of "2" like we can do in Javascript ? ex:

    for(var i=0;i<array.length();i += 2)

回答1:


You should put v-layout outside of v-for

  <div class="mr-4 ml-4 whiteback userGroupHeight">
          <v-layout row wrap>
                <v-flex v-for="(category,index) in types" :key="types[index].text" xs6>
                  <v-checkbox light :label="category.text" v-model="category.selected">
                  </v-checkbox>
                </v-flex>
          </v-layout>
</div>

then you don't need to use checkLength method.

Demo: https://codepen.io/ittus/pen/ZRqYME



来源:https://stackoverflow.com/questions/51052395/display-multiple-checkbox-in-table-format-using-v-for-and-v-checkbox-in-vuet

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!