Treeview - 图1

Treeview Vue Component

Treeview Vue component represents Framework7’s Treeview component.

Treeview Components

There are following components included:

  • f7-treeview - main treeview container
  • f7-treeview-item - treeview item

Treeview Properties

PropTypeDefaultDescription
<f7-treeview-item> properties
togglebooleanEnables treeview item toggle button. By default enabled if there are children item
itemTogglebooleanfalseEnables whole treeview item as toggle
selectablebooleanfalseMakes item selectable
selectedbooleanMakes item selected
openedbooleanfalseDefines whether the item opened by default or not
labelstringItem label text
loadChildrenbooleanfalseEnable when you need to load children items on open.
linkstring
boolean
Enables link and link URL if specified as string. Same as href attribute
<f7-treeview-item> icon related properties
icon-sizestring
number
Icon size in px
icon-colorstringIcon color. One of the default colors
iconstringCustom icon class
icon-f7stringName of F7 Icons font icon
icon-materialstringName of Material Icons font icon
icon-iosstringIcon to be used in case of iOS theme is used. Consists of icon family and icon name divided by colon, e.g. f7:home
icon-mdstringIcon to be used in case of MD theme is used. Consists of icon family and icon name divided by colon, e.g. material:home
icon-aurorastringIcon to be used in case of Aurora theme is used. Consists of icon family and icon name divided by colon, e.g. material:home
<f7-treeview-item> navigation/router related properties
hrefstring
boolean
#URL of the page to load. In case of boolean href=”false” it won’t add href tag
targetstringValue of link target attribute, e.g. _blank, _self, etc.
viewstringCSS selector of the View to load the page. Or current to load in current view.
externalbooleanEnable to bypass Framework7’s link click handler
backbooleanEnables back navigation link
forcebooleanForce page to load and ignore previous page in history (use together with back prop)
reload-currentbooleanReloads new page instead of the currently active one
reload-previousbooleanReplace the previous page in history with the new one from route
reload-allbooleanLoad new page and remove all previous pages from history and DOM
reload-detailbooleanReload Detail page in Master Detail view
animatebooleanDisables pages animation
transitionstringName of the custom page transition
ignore-cachebooleanIgnores caching
route-tab-idstringRoutable Tab id
route-propsobjectObject with additional props that will be passed to target route component
prevent-routerbooleanfalseIf set, then it won’t be processed by Framework7 router
<f7-treeview-item> action related properties
panel-openstring
boolean
CSS selector of panel to open on click. Or can be left or right if there is only left or right panel in DOM.
panel-closestring
boolean
Closes panel on click
panel-togglestring
boolean
CSS selector of panel to toggle on click. Or can be left or right if there is only left or right panel in DOM.
actions-openstring
boolean
CSS selector of the action sheet to open on click
actions-closestring
boolean
CSS selector of the action sheet to close on click. Or boolean property to close currently opened action sheet
popup-openstring
boolean
CSS selector of the popup to open on click
popup-closestring
boolean
CSS selector of the popup to close on click. Or boolean property to close currently opened popup
popover-openstring
boolean
CSS selector of the popover to open on click
popover-closestring
boolean
CSS selector of the popover to close on click. Or boolean property to close currently opened popover
sheet-openstring
boolean
CSS selector of the sheet modal to open on click
sheet-closestring
boolean
CSS selector of the sheet modal to close on click. Or boolean property to close currently opened sheet modal
login-screen-openstring
boolean
CSS selector of the login screen to open on click
login-screen-closestring
boolean
CSS selector of the login screen to close on click. Or boolean property to close currently opened login screen
sortable-enablestring
boolean
CSS selector of the Sortable list to open on click
sortable-disablestring
boolean
CSS selector of the Sortable list to close on click. Or boolean property to close currently opened Sortable list
sortable-togglestring
boolean
CSS selector of the Sortable list to toggle on click. Or boolean property to toggle currently opened/closed Sortable list
searchbar-enablestring
boolean
CSS selector of the Expandable Searchbar to be enabled on click. Or boolean property to enable the first found Searchbar
searchbar-disablestring
boolean
CSS selector of the Expandable Searchbar to be disabled on click. Or boolean property to disable the first found Searchbar
searchbar-togglestring
boolean
CSS selector of the Expandable Searchbar to toggle on click. Or boolean property to toggle the first found Searchbar
searchbar-clearstring
boolean
CSS selector of the Expandable Searchbar to clear on click. Or boolean property to clear the first found Searchbar
card-openstring
boolean
CSS selector of the expandable card to open on click. Or boolean to open first found expandable card
card-closestring
boolean
CSS selector of the expandable card to close on click. Or boolean property to close currently opened expandable card
card-prevent-openbooleanClick on element with this prop won’t open its parent expandable card
menu-closebooleanCloses Menu dropdown on click

Treeview Events

EventDescription
<f7-treeview-item> events
clickEvent will be triggeres when user clicks on treeview item
treeview:openEvent will be triggered on item open
treeview:closeEvent will be triggered on item close
treeview:loadchildrenEvent will be triggered on first open of Treeview item with loadChildren prop. In event.detail it contains function to hide loading preloader.

Treeview Item Slots

Treeview Vue component (<f7-treeview-item>) has additional slots for custom elements:

  • root-start - element will be inserted in the beginning of treeview item element
  • root / root-end - element will be inserted in the end of treeview item element
  • content-start - element will be inserted in the beginning of <div class="treeview-item-content"> element
  • content / content-end - element will be inserted in the end of <div class="treeview-item-content"> element
  • children-start - element will be inserted in the beginning of the <div class="treeview-item-children"> element
  • default - element will be inserted in the end of the <div class="treeview-item-children"> element
  • media - element will be inserted before <div class="treeview-item-label"> element
  • label-start - element will be inserted in the beginning <div class="treeview-item-label"> element
  • label - element will be inserted in the end of <div class="treeview-item-label"> element
  1. <f7-treeview-item label="Item 1">
  2. <img src="path-to-my-image.jpg" slot="media">
  3. <div slot="root-start">Root Start</div>
  4. <div slot="root">Root End</div>
  5. <div slot="content-start">Content Start</div>
  6. <div slot="content">Content End</div>
  7. <span slot="label-start">Before Label</span>
  8. <f7-treeview-item label="Sub Item 1" />
  9. ...
  10. </f7-treeview-item>
  11. <!-- Renders to: -->
  12. <div class="treeview-item">
  13. <div class="treeview-item-root">
  14. <div>Root Start</div>
  15. <div class="treeview-toggle"></div>
  16. <div class="treeview-item-content">
  17. <div>Content Start</div>
  18. <img src="path-to-my-image.jpg">
  19. <div class="treeview-item-label">
  20. <span>Before Label</span>
  21. Item 1
  22. </div>
  23. <div>Content End</div>
  24. </div>
  25. </div>
  26. <div class="treeview-item-children">
  27. <div class="treeview-item">
  28. <div class="treeview-item-root">
  29. <div class="treeview-item-content">
  30. <div class="treeview-item-label">Sub Item 1</div>
  31. </div>
  32. </div>
  33. </div>
  34. ...
  35. </div>
  36. <div>Root End</div>
  37. </div>

Examples

  1. <template>
  2. <f7-page>
  3. <f7-navbar title="Treeview" />
  4. <f7-block-title>Basic tree view</f7-block-title>
  5. <f7-block strong class="no-padding-horizontal">
  6. <f7-treeview>
  7. <f7-treeview-item label="Item 1">
  8. <f7-treeview-item label="Sub Item 1">
  9. <f7-treeview-item label="Sub Sub Item 1" />
  10. <f7-treeview-item label="Sub Sub Item 2" />
  11. </f7-treeview-item>
  12. <f7-treeview-item label="Sub Item 2">
  13. <f7-treeview-item label="Sub Sub Item 1" />
  14. <f7-treeview-item label="Sub Sub Item 2" />
  15. </f7-treeview-item>
  16. </f7-treeview-item>
  17. <f7-treeview-item label="Item 2">
  18. <f7-treeview-item label="Sub Item 1">
  19. <f7-treeview-item label="Sub Sub Item 1" />
  20. <f7-treeview-item label="Sub Sub Item 2" />
  21. </f7-treeview-item>
  22. <f7-treeview-item label="Sub Item 2">
  23. <f7-treeview-item label="Sub Sub Item 1" />
  24. <f7-treeview-item label="Sub Sub Item 2" />
  25. </f7-treeview-item>
  26. </f7-treeview-item>
  27. <f7-treeview-item label="Item 3" />
  28. </f7-treeview>
  29. </f7-block>
  30. <f7-block-title>With icons</f7-block-title>
  31. <f7-block strong class="no-padding-horizontal">
  32. <f7-treeview>
  33. <f7-treeview-item label="images" icon-f7="folder_fill">
  34. <f7-treeview-item label="avatar.png" icon-f7="photo_fill" />
  35. <f7-treeview-item label="background.jpg" icon-f7="photo_fill" />
  36. </f7-treeview-item>
  37. <f7-treeview-item label="documents" icon-f7="folder_fill">
  38. <f7-treeview-item label="cv.docx" icon-f7="document_text_fill" />
  39. <f7-treeview-item label="info.docx" icon-f7="document_text_fill" />
  40. </f7-treeview-item>
  41. <f7-treeview-item label=".gitignore" icon-f7="logo_github" />
  42. <f7-treeview-item label="index.html" icon-f7="document_text_fill" />
  43. </f7-treeview>
  44. </f7-block>
  45. <f7-block-title>With checkboxes</f7-block-title>
  46. <f7-block strong class="no-padding-horizontal">
  47. <f7-treeview>
  48. <f7-treeview-item label="images" icon-f7="folder_fill">
  49. <f7-checkbox slot="content-start"
  50. :checked="Object.values(checkboxes.images).indexOf(false) < 0"
  51. :indeterminate="Object.values(checkboxes.images).indexOf(false) >= 0 && Object.values(checkboxes.images).indexOf(true) >= 0"
  52. @change="(e) => Object.keys(checkboxes.images).forEach(k => checkboxes.images[k] = e.target.checked)"
  53. />
  54. <f7-treeview-item label="avatar.png" icon-f7="photo_fill">
  55. <f7-checkbox slot="content-start"
  56. :checked="checkboxes.images['avatar.png']"
  57. @change="checkboxes.images['avatar.png'] = $event.target.checked"
  58. />
  59. </f7-treeview-item>
  60. <f7-treeview-item label="background.jpg" icon-f7="photo_fill">
  61. <f7-checkbox slot="content-start"
  62. :checked="checkboxes.images['background.jpg']"
  63. @change="checkboxes.images['background.jpg'] = $event.target.checked"
  64. />
  65. </f7-treeview-item>
  66. </f7-treeview-item>
  67. <f7-treeview-item label="documents" icon-f7="folder_fill">
  68. <f7-checkbox slot="content-start"
  69. :checked="Object.values(checkboxes.documents).indexOf(false) < 0"
  70. :indeterminate="Object.values(checkboxes.documents).indexOf(false) >= 0 && Object.values(checkboxes.documents).indexOf(true) >= 0"
  71. @change="(e) => Object.keys(checkboxes.documents).forEach(k => checkboxes.documents[k] = e.target.checked)"
  72. />
  73. <f7-treeview-item label="cv.docx" icon-f7="document_text_fill">
  74. <f7-checkbox slot="content-start"
  75. :checked="checkboxes.documents['cv.docx']"
  76. @change="checkboxes.documents['cv.docx'] = $event.target.checked"
  77. />
  78. </f7-treeview-item>
  79. <f7-treeview-item label="info.docx" icon-f7="document_text_fill">
  80. <f7-checkbox slot="content-start"
  81. :checked="checkboxes.documents['info.docx']"
  82. @change="checkboxes.documents['info.docx'] = $event.target.checked"
  83. />
  84. </f7-treeview-item>
  85. </f7-treeview-item>
  86. <f7-treeview-item label=".gitignore" icon-f7="logo_github">
  87. <f7-checkbox slot="content-start"
  88. :checked="checkboxes['.gitignore']"
  89. @change="checkboxes['.gitignore'] = $event.target.checked"
  90. />
  91. </f7-treeview-item>
  92. <f7-treeview-item label="index.html" icon-f7="document_text_fill">
  93. <f7-checkbox slot="content-start"
  94. :checked="checkboxes['index.html']"
  95. @change="checkboxes['index.html'] = $event.target.checked"
  96. />
  97. </f7-treeview-item>
  98. </f7-treeview>
  99. </f7-block>
  100. <f7-block-title>Whole item as toggle</f7-block-title>
  101. <f7-block strong class="no-padding-horizontal">
  102. <f7-treeview>
  103. <f7-treeview-item item-toggle label="images" icon-f7="folder_fill">
  104. <f7-treeview-item label="avatar.png" icon-f7="photo_fill" />
  105. <f7-treeview-item label="background.jpg" icon-f7="photo_fill" />
  106. </f7-treeview-item>
  107. <f7-treeview-item item-toggle label="documents" icon-f7="folder_fill">
  108. <f7-treeview-item label="cv.docx" icon-f7="document_text_fill" />
  109. <f7-treeview-item label="info.docx" icon-f7="document_text_fill" />
  110. </f7-treeview-item>
  111. <f7-treeview-item label=".gitignore" icon-f7="logo_github" />
  112. <f7-treeview-item label="index.html" icon-f7="document_text_fill" />
  113. </f7-treeview>
  114. </f7-block>
  115. <f7-block-title>Selectable</f7-block-title>
  116. <f7-block strong class="no-padding-horizontal">
  117. <f7-treeview>
  118. <f7-treeview-item
  119. selectable
  120. :selected="selectedItem === 'images'"
  121. label="images"
  122. icon-f7="folder_fill"
  123. @click="toggleSelectable($event, 'images')"
  124. >
  125. <f7-treeview-item
  126. selectable
  127. :selected="selectedItem === 'avatar.png'"
  128. label="avatar.png"
  129. icon-f7="photo_fill"
  130. @click="toggleSelectable($event, 'avatar.png')"
  131. />
  132. <f7-treeview-item
  133. selectable
  134. :selected="selectedItem === 'background.jpg'"
  135. label="background.jpg"
  136. icon-f7="photo_fill"
  137. @click="toggleSelectable($event, 'background.jpg')"
  138. />
  139. </f7-treeview-item>
  140. <f7-treeview-item
  141. selectable
  142. :selected="selectedItem === 'documents'"
  143. label="documents"
  144. icon-f7="folder_fill"
  145. @click="toggleSelectable($event, 'documents')"
  146. >
  147. <f7-treeview-item
  148. selectable
  149. :selected="selectedItem === 'cv.docx'"
  150. label="cv.docx"
  151. icon-f7="document_text_fill"
  152. @click="toggleSelectable($event, 'cv.docx')"
  153. />
  154. <f7-treeview-item
  155. selectable
  156. :selected="selectedItem === 'info.docx'"
  157. label="info.docx"
  158. icon-f7="document_text_fill"
  159. @click="toggleSelectable($event, 'info.docx')"
  160. />
  161. </f7-treeview-item>
  162. <f7-treeview-item
  163. selectable
  164. :selected="selectedItem === '.gitignore'"
  165. label=".gitignore"
  166. icon-f7="logo_github"
  167. @click="toggleSelectable($event, '.gitignore')"
  168. />
  169. <f7-treeview-item
  170. selectable
  171. :selected="selectedItem === 'index.html'"
  172. label="index.html"
  173. icon-f7="document_text_fill"
  174. @click="toggleSelectable($event, 'index.html')"
  175. />
  176. </f7-treeview>
  177. </f7-block>
  178. <f7-block-title>Preload children</f7-block-title>
  179. <f7-block strong class="no-padding-horizontal">
  180. <f7-treeview>
  181. <f7-treeview-item
  182. toggle
  183. load-children
  184. icon-f7="persons"
  185. label="Users"
  186. @treeview:loadchildren="loadChildren"
  187. >
  188. <f7-treeview-item
  189. v-for="(item, index) in loadedChildren"
  190. :key="index"
  191. icon-f7="person"
  192. :label="item.name"
  193. />
  194. </f7-treeview-item>
  195. </f7-treeview>
  196. </f7-block>
  197. <f7-block-title>With links</f7-block-title>
  198. <f7-block strong class="no-padding-horizontal">
  199. <f7-treeview>
  200. <f7-treeview-item icon-f7="data_fill" item-toggle label="Modals">
  201. <f7-treeview-item link="/popup/" icon-f7="link" label="Popup" />
  202. <f7-treeview-item link="/dialog/" icon-f7="link" label="Dialog" />
  203. <f7-treeview-item link="/action-sheet/" icon-f7="link" label="Action Sheet" />
  204. </f7-treeview-item>
  205. <f7-treeview-item icon-f7="data_fill" item-toggle label="Navigation Bars">
  206. <f7-treeview-item link="/navbar/" icon-f7="link" label="Navbar" />
  207. <f7-treeview-item link="/toolbar-tabbar/" icon-f7="link" label="Toolbar & Tabbar" />
  208. </f7-treeview-item>
  209. </f7-treeview>
  210. </f7-block>
  211. </f7-page>
  212. </template>
  213. <script>
  214. import { f7Page, f7Navbar, f7BlockTitle, f7Block, f7Treeview, f7TreeviewItem, f7Checkbox } from 'framework7-vue';
  215. export default {
  216. components: {
  217. f7Page, f7Navbar, f7BlockTitle, f7Block, f7Treeview, f7TreeviewItem, f7Checkbox
  218. },
  219. data: function () {
  220. return {
  221. checkboxes: {
  222. images: {
  223. 'avatar.png': false,
  224. 'background.jpg': false,
  225. },
  226. documents: {
  227. 'cv.docx': false,
  228. 'info.docx': false,
  229. },
  230. '.gitignore': false,
  231. '.index.html': false,
  232. },
  233. selectedItem: null,
  234. loadedChildren: [],
  235. };
  236. },
  237. methods: {
  238. toggleSelectable: function (e, item) {
  239. var self = this;
  240. var $ = self.$$;
  241. if ($(e.target).is('.treeview-toggle')) return;
  242. self.selectedItem = item;
  243. },
  244. loadChildren: function (e, done) {
  245. var self = this;
  246. setTimeout(function () {
  247. // call done() to hide preloader
  248. done();
  249. self.loadedChildren = [
  250. {
  251. name: 'John Doe',
  252. },
  253. {
  254. name: 'Jane Doe',
  255. },
  256. {
  257. name: 'Calvin Johnson',
  258. },
  259. ];
  260. }, 2000);
  261. },
  262. },
  263. };
  264. </script>

← Toolbar / Tabbar

View →